TwelvestoneFlash

AS3 non-display class to Document root (oop help)


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
blacksanta_69
 
2008-06-27

I'm sure this has been posted about before: any help would be appreciated.

I have a document root as follows:

package{ import childSound; import flash.display.MovieClip;

public class Main extends MovieClip{
    private var cs:childSound;
    public function Main(){
        cs = new childSound();
    }
    public function superTrace(msg:String):void{
        trace(msg);
    }
}

}

That imports the following class

package{ import flash.media.Sound; public class childSound extends Sound{ public function childSound(){ Main(root).superDebug("TestThis"); } } }

Is it possible to call a function in the documentroot from a class that isn't "addChild"ed? Can I do something like add text to a text box from the childSound class instead of a display object (say for debugging a netStatus event or something)

DontBogartMe
 
2008-06-27

in your example Main creates an instance of the childSound class - that's a one-way conversation there: Main can get childSound to do things and it can know stuff about childSound because it instantiated it - but childSound can't know about whatever it was that instantiated it. There must be some OOP words to describe that, but I can't think what they are right now k

What I would do here is to make childSound so it can broadcast events (implements IEventDispatcher), then Main can listen for those events. E.g. childSound could broadcast an event NETSTATUSUPDATED which would send over some data about what happened to netStatus, and Main could listen for that event. When the event happens, Main then reacts by drawing that text box itself and fills it with the text sent in the event from childSound.

pyrogen
 
2008-06-29

Add an event listener to cs instance, and create a custom event in you sound class that dispatches whatever ya need.

The man doc eventhandler you have added to you custm event listener will do whatever ya need

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

AS3 non-display class to Document root (oop help)