Don’t trust Stage.width
28 Feb07
Just found an issue with cached SWF files in IE7 - Stage.width will sometimes be reported incorrectly. We had a Movieclip that used Stage.width for positioning and whenever the SWF was cached, that movieclip would be positioned off stage. Hardcoding a variable instead of using the property solved the problem.
I seem to remember that there were some issues with Stage.width some years ago as well? Anyway - great to finally be doing some Flash work after editing JSP and portlets the last couple months…
28 February 2007 at 8:04 pm
If I recall correctly, you have to wait a frame for the Stage props to instantiate correctly. Putting all your code on frame 2 - or putting in a wait generally fixes these issues.
Generally, you can get around weird stage size problems by listening for it’s resize event and doing your positioning in the event handler. At least one of the browsers out there doesn’t report the correct value when the SWF first starts playing.
Hi Mike,
Sounds probable, but unfortunatly it won’t work for me. I don’t use frames at all since I only do class based stuff using FlashDevelop and all my code is usually on frame one.
I think Josh’s idea will work, since the resize event should trigger after the first frame is drawn. Thanks for good pointers!
The odd thing is that if I trace the value to a text field in the faulty SWF, it will report the correct value despite failing to position the MC? Odd…
Use interval instead of frames and wait couple ms for “initialization”. You can do it gracefully with setInterval and dispatching custom event (sceneInitialized, or sth). In event handler write your code for layouting.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
{
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener( “resize”, onWindowResize );
//dbg
}
{
}
}
}