A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Constructor Functions

  1. #1
    Member
    Join Date
    Jun 2007
    Posts
    41

    Constructor Functions

    If you set up a link between a symbol and a class, how do you call the constructor function?

    There are cases in my movie where I have a MC symbol already on the stage, but before anything happens in the movie, I need to gather information about the MC's children, and I need a constructor like function to do so.(My methods contain elements that arent defined in the class at compile time, but I cannot define them without first running a function to collect information about them)

    There are also other times where I am dynamically creating instances of another type of MC,(different from above) and I need to pass information into the MC and also set it up as a Listener, but I do not know the parent of the calling function at compile time, and need to pass this MC the name of the parent calling function, and then register it as a listener.

    I really dont want to hack this, and was wondering if anyone knows a clean way to do this. I am already knee deep in code, so multiple suggestions would be desired, just in case one suggestion wont work with the way I already have things running.

    Thanks

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    when an instance of the symbol associated with the class is on stage the associated construtor function is automatically called...u dont need to explicity call it

    when u dynamically attach a moveiclip to the stage, u can pass in parameters to the constructor function using the initObject e.g suppose u wanted to intialise a color property defiend in the class:

    this.attachMovie("myName", "myName", 1, {color:0xFFFFF});
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Member
    Join Date
    Jun 2007
    Posts
    41
    What is wrong with this? This is the class that has been linked to the MovieClip. I have tried making this class extend AsBroadcaster, but for some reason the functionality of the class changes, and the entire movieclip no longer works the way it is suppose to, so instead I use initialize

    Code:
    class Manage {
    
    function Manage () {
    		AsBroadcaster.initialize(this);
    	}
    
    function check() {
         if (condition) {
                    broadcastMessage("raise", 5);
              }
         }
    }

    I then use another function to register listeners.

  4. #4
    Member
    Join Date
    Jun 2007
    Posts
    41
    Now I cant even get my movieclips to be created. I dont know what happened, but now this is not working...

    Code:
    var i=0;
    
    while (array1[i]) {
    
    var Init:Object = new Object();
    Init._x = array1[i];
    Init._y = array2[i];
    
    _root.SomeMovieClip.attachMovie("NewRow", "NewRow" + i, _root.SomeMovieClip.getNextHighestDepth(), Init)
    
    i++;
    
    }
    with NewRow being a symbol linked to a class that is created after a database query and SomeMovieClip holding all of the NewRow instances. The loop is working properly, and different values are being loaded into Init on each pass as seen through a trace function, but none of the movieclips are appearing on stage, and the debugger shows no instance of them

    Does anyone have a better way of doing anything that I have shown in my last couple of posts.

    Thanks
    Last edited by cpetzol2; 06-15-2007 at 12:12 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center