Skip to main content
Known Participant
February 23, 2010
Answered

Height and Width are 0?

  • February 23, 2010
  • 1 reply
  • 527 views

I want to write a shell that creates instances of an app and scales it down for animating. Well, I'm new at this so I created my shell class and instanced the app and set scales for x and y and then I traced the height and width because I wasn't sure what they'd be. I thought they'd be based on the stuff on the stage or whatever, but they both came up zero. So I'm not sure how that works, am I supposed to have set those values?

I know this is pretty n00b, but yeah, I'm new at this.

public class MWShell extends MovieClip
{
  private var mWall:MonitorWallApp;
 
  public function MWShell()
  {
   mWall = new MonitorWallApp();
  
   mWall.scaleX = .6;
   mWall.scaleY = .6;
   
   trace(mWall.height, " ", mWall.width);
  
   addChild(mWall);
  
  
 
  
  }
 
}

This topic has been closed for replies.
Correct answer kglad

if MonitorWallApp has no content until it loads an external file, you would expect its width and height to be zero until loading is complete.

ie, use a complete listener in MonitorWallApp and dispatch that event outside your class.  add a listener to your instances so you know when loading is complete outside your class.

1 reply

kglad
Community Expert
Community Expert
February 23, 2010

try:


public class MWShell extends MovieClip
{
  private var mWall:MonitorWallApp;
 
  public function MWShell()
  {
   mWall = new MonitorWallApp();

   addChild(mWall);


  
   mWall.scaleX = .6;
   mWall.scaleY = .6;
   
   trace(mWall.height, " ", mWall.width);
  
  
  
 
  
  }
 
}

Known Participant
February 23, 2010

Hmm, nope, that didn't work. But I think I might know what's up. The class I'm instantiating has a couple of graphics to load so I'm thinking that by the time I'm tracing out the height and width, my instance doesn't have anything on stage yet.

So, does that mean I should come up with some event to broadcast from the instance class? Or should I check every frame or so to see if the height and width change?

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 23, 2010

if MonitorWallApp has no content until it loads an external file, you would expect its width and height to be zero until loading is complete.

ie, use a complete listener in MonitorWallApp and dispatch that event outside your class.  add a listener to your instances so you know when loading is complete outside your class.