Every class I create from an asset in ActionScript 3 has a width and height which are both 0. If I set a value and then immediately trace it, the output is zero. The class is valid and the code runs, it just doesn’t display anything. (Unless I use graphics methods.) Additionally, it remains locked at frame 0.
screenshot of the setup http://img266.imageshack.us/img266/9799/flashwtf.png
// in the main SWF class
titleScreen = new TitleScreen();
addChild(titleScreen);
trace("w: ", titleScreen.width, ", h: ", titleScreen.height);
titleScreen.width = 550;
titleScreen.height = 400;
trace("w: ", titleScreen.width, ", h: ", titleScreen.height);
Expected Output:
w: 200, h: 123
w: 550, h: 400
Actual output:
w: 0, h: 0
w: 0, h: 0
It’s because I’m exporting classes in frame 200. I did this in order to preload, which I did. But even when the entire document was loaded, width and height were locked at zero.
Solution: After preloading (the main instance’s loaderInfo .bytesLoaded >= .bytesTotal), call the main instance’s .gotoAndStop(200). (or whatever frame you exported classes in.) At this point all your classes and objects will be valid.