Reputation: 1299
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
Upvotes: 0
Views: 2941
Reputation: 18546
The creationComplete
complete event fires when it has been added to a display list, not necessarily the Stage's display list. creationComplete
fires when that this object and all of its children have been created and added to something.
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.
Note that creationComplete
will only fire once after instantiating an object and adding it as a child to something, where addedToStage
will fire any time that it gets added to the stage (in the case that it gets removed and re-added later without reconstucting the object).
See this blog post for some more details on the subject.
Upvotes: 4