在Firefox 3.5上没有获得stage.stageWidth和stageHeight

时间:2010-05-31 16:04:04

标签: flash firefox actionscript-3

这是一个问题,我一直试图弄清楚,但仍然无法找到正确的解决方法。

我在MAC上使用Firefox 3.5时遇到显示问题,我可以看到我的菜单和显示是否正确。菜单位于它应该定位的位置之上。它适用于MACOSX上的Safari。 我的闪光灯尺寸是:1440x750

看起来Firefox无法识别stage.StageWidth和stage.StageHeight。它返回0。

有人建议实现是通过FlashVars传递电影的实际宽度和高度。电影使用这些而不是stage.stageWidth和stage.stageHeight

有没有人有如何修复该问题的代码示例? 赞赏地指出了正确的方法


我是否以正确的方式使用EnterFrame方法?

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_FRAME, 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);
 } 

1 个答案:

答案 0 :(得分:1)

问题是,当SWF加载时,阶段大小变量通常需要几毫秒才能设置,因此如果定位菜单的代码在初始化之前运行,它将看到宽度和高度为0。

解决此问题的方法是设置一个EnterFrame侦听器,该侦听器将检查每个帧以查看是否已设置舞台尺寸,并且当它们具有时,它将调用您的定位代码。

以下是如何完成的:

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
}
相关问题