Here's a problem that I've been tried to figure out but still couldn't get the right method to fix it yet.
I'm having issue regarding the display when using Firefox 3.5 on MAC, I can see my menu and the display is correct. The menu just position above what it supposed to be positioned. It works fine with Safari on MACOSX. My flash size is: 1440x750
It looks like Firefox can't recognize stage.StageWidth and stage.StageHeight. It returns 0.
Some suggest implementing was to pass in the actual width and height of movie via FlashVars. The movie uses these instead of stage.stageWidth and stage.stageHeight
Does anyone have an example of code of how to fix that issue?? Appreciated to point me out the right way
Am I using the right way with EnterFrame method??
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, handleOnStage, false, 0, true);
}
private function handleOnStage(event:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, handleOnStage);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, handleResizeObjectsOnStage, false, 0, true);
addEventListener(Event.ENTER_FRAM开发者_运维知识库E, handleObjectsOnStage, false, 0, true);
bottomBarMC.x = 0;
bottomBarMC.y = 0;
}
private function handleObjectsOnStage(event:Event):void
{
if (stage.stageWidth != 0 && stage.stageHeight != 0) {
removeEventListener(Event.ENTER_FRAME, handleObjectsOnStage);
initIntro();
initObjectsOnStage();
}
}
private function handleResizeObjectsOnStage(event:Event=null):void
{
if (stage.stageWidth != 0 && stage.stageHeight != 0) {
initObjectsOnStage();
}
}
private function initObjectsOnStage():void
{
// Resize dynamically bottomBarMC
bottomBarMC.width = stage.stageWidth;
bottomBarMC.height = stage.stageHeight;
addChild(bottomBarMC);
// Resize dynamically logo
logoMC.x = 40;
logoMC.y = stage.stageHeight - 100;
addChild(logoMC);
var loadIntro:Sprite = getCurrentMC();
//loadIntro.x = stage.stageWidth;
//loadIntro.y = 0;
addChild(loadIntro);
}
The problem is that the stage size variables often take a few milliseconds to be set while the SWF loads, so if the code positioning the menu runs before they are initialized, it will see a width and height of 0.
The method to get around this is to set an EnterFrame listener that will check each frame to see if the stage dimensions have been set, and when they have, it will call your positioning code.
Here is how it is done:
public function MainDocumentClass()
{
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
public function onEnterFrame(e:Event):void
{
if (stage.stageWidth != 0 && stage.stageHeight != 0)
{
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
onStageInitialized();
}
}
public function onStageInitialized():void
{
//put your menu positioning here
}
精彩评论