2010-05-31 25 views
0

這裏的,我一直在試圖找出,但仍不能得到正確的方法來解決這個問題還沒有問題。沒有得到stage.stageWidth和stageHeight在Firefox 3.5

我在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

的問題是,舞臺的大小變量往往需要幾毫秒到設置而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 
} 
+0

如果我想包括將Stage.align,在Stage.scaleMode和stage.addEventListener。 我應該把他們放在哪裏? stage.align = StageAlign.TOP_LEFT; stage.scaleMode \t = StageScaleMode.NO_SCALE; \t \t \t stage.addEventListener(Event.RESIZE,handleResizeObjectsOnStage,false,0,true); – Qpixo 2010-06-07 19:04:32

+0

如果您正在使用外部AS文件,請將其放在文檔類的構造函數的頂部。 如果你只是在Flash IDE工作時間表,然後把它放在第1幀的主時間軸上。 – 2010-06-07 21:31:22