|
-
[CS3] ActionScript 3: how do I access the stage properties from a .as file?
I'm restarting from square one with AS 3, since I got over my head with all the OOP stuff when I first dove in, and I want to do this right. I want to write a very simple app as a first exercise. I have a .fla file (Keepaway_applet.fla) whose Document Class is set to "Keepaway". In this Flash file's library (not on the stage) is a symbol which has been given the Class "Background". This symbol is just a rectangle. I also have a file "Keepaway.as", in the same folder as the .fla file.
I want Keepaway.as to put an instance of Background onto the stage and size it to the stage, but I can't access the stage properties of Keepaway_applet.fla from the .as file. When I run the following code in Keepaway.as, the Background symbol properly appears at the upper left of the stage, but at its original size. That is, its width and height are not being set to the stage width and height.
Code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Keepaway extends MovieClip {
public function Keepaway() {
var theBackground:Background = new Background;
addChild(theBackground);
theBackground.x = theBackground.y = 0; // put reg at upper left of stage
theBackground.width = stage.width;
theBackground.height = stage.height;
}
}
}
I also tried
Code:
theBackground.width = theBackground.stage.width;
theBackground.height = theBackground.stage.height;
My understanding was that you had to access the stage through some display object on the stage, which is why I tried putting the AddChild() statement before doing the sizing. But I'd rather size the rectangle to the stage size first, then add it to the Display list.
Can anyone tell me what I'm doing wrong?
As always, thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|