大家下午好,
我在用adobe air(flex sdk 4.6.0)創建一個android應用程序,我試圖找出手機屏幕的寬度是以像素爲單位的。所以我正在休學教程here,但是當我將代碼複製到我的項目中並單擊運行時,它總是給我這個錯誤「TypeError:Error#1009:Can not access a property or method of null object reference。」並去了stage.stageWidth我也試過stage.width但它做同樣的事情。那麼stage.stageWidth不再有效,或者你如何判斷平板電腦或手機的屏幕尺寸?它是否替換爲手機的其他東西?我正在嘗試獲取信息,以便我可以使用操作腳本將圖像集中在屏幕的中心。爲什麼在android上使用flex的flash Builder 4.6中的stage.stageWidth不起作用?
protected function init():void {
//function run at creationComplete="init()"
movePhotoToCenter(myIMG1);
// trying to get the stage width so that i can center a img that is allready added to the flex code and has a id of "myIMG1"
}
protected function movePhotoToCenter(img:Image):void {
//"error here" where im centering the image
var centerOfStage:Number = stage.stageWidth/2;
var Xnumber:Number = centerOfStage - (img.width/2);
trace(Xnumber);
var move:Move = new Move(img);
move.xFrom = img.x;
move.xTo = Xnumber;
move.yFrom = img.y;
move.yTo = img.y;
move.duration = 3000;
move.play();
trace(img.width);
img.scaleX=1;
img.scaleY=1;
trace(img.width);
}
感謝您的幫助, 賈斯汀
當「DisplayObject」已添加到舞臺上時,'stage'僅爲空。您是否確定在舞臺上知道它的時候(通常是等待「ADDED_TO_STAGE」事件),在上下文中進行評估? – 2012-01-11 17:18:52
我在創建完成事件中運行它。 init():void {stage.stageHeight; }我需要什麼直到事後得到舞臺降級? – Justin 2012-01-11 17:26:45
編輯你的問題,並添加你的班級的相關部分 – 2012-01-11 17:29:00