English 中文(简体)
为什么确实如此。 阶段 闪电4.6号,使用软体而不是工作吗?
原标题:Why does stage.stageWidth in flash Builder 4.6 using flex on android not work?

Good afternoon,
I am creating a android app using adobe air (flex sdk 4.6.0) and i am trying to find out what the width of the phone screen is in pixels. So I am fallowing the tutorial here but when ever i copy the code into my project and click run it always gives me this error "TypeError: Error #1009: Cannot access a property or method of a null object reference." and goes to the line that has stage.stageWidth I have also tried stage.width but it does the same thing. So does stage.stageWidth no longer work or how do you tell the screen size of the tablet or phone? Was it replaced with something else for phones? I am trying to get the information so i can center images in the center of the screen using action script.

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

Thanks for you help, Justin

问题回答

。 在a显示清单中添加完整的活动火灾,不一定是Stage显示清单>。

There is another event to bind to called addedToStage (in flex land anyway), that will occur when the DisplayObject has actually been added to the stage.

请注意,<条码>娱乐/代码>只有在一物体被当即发并作为儿童添加到某种东西之后,才会发生火灾,<条码> 添加时,该代码将发射任何添加到该阶段的时间(如果该物体在以后被拆除并重新添加而未重新插入该物体)。

See ,this blog post , for some more details on the subject.





相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签