Skip navigation
Currently Being Moderated

add event listeners to child's child

Apr 14, 2012 8:33 AM

Tags: #class #as3 #event #height #child #width #parent



I have this little class where I load up a loader and turn it into a movieclip (along with some other stuff).

I also have this bigger class where I have a bunch of the little classes.  And in trying to lay them out properly, I use their width and height and stuff.

But I guess since it takes time for the little classes to load up and convert to movieclip along with the other stuff,  when I access the width and height of them in the big class, they're all zero.

What I'm doing now is kind of ugly where after I convert/add the movieclip,  I dispatch bubbling event in the smaller class, and literally add them up in the parent class until they're all done.

What I tried doing was adding Event.ADDED to movieclip variable in the little classes, from the big class.


But that didn't work and was just as ugly!


So basically my question is... what do I do in either the child class or the parent class so that... I can just create it, add it, and have all the objects width and height and stuff ready right off the bat(no matter now many movieclips, loaders, sounds, sprites in the smaller class)?


Like a dispatch "ok everything is all done here, now you can access my width and height accurately"

  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 14, 2012 9:27 AM   in reply to clammyclam

    you must wait until loading is complete to access width/height properties of the loaded content.  ie, use an Event.COMPLETE listener.

    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 7:11 AM   in reply to clammyclam

    what is new laptop.inbox("1")?


    if that's a library symbol that contains a component, then use the render event, or that contains shapes in a frame other than 1 that contribute to the width/height you're trying to access, then dispatch an event from a frame other than one, use a callback function.


    if that's a class in which you construct objects, then dispatch and event or use a callback function, when the width and height are ready to be accessed.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points