How do you create an instance of an object on the stage using actionscript only?
Hi everyone! So I am working on a project using Adobe Animate, imitating a Youtube tutorial about using Flash 3.
The author says the following code is functionally equivalent to dragging a symbol onto the stage:
Package {
import flash.display.MovieClip;
public class Main extends MovieClip {
var flyer:Flyer = new Flyer();
public function Main() {
startGame();
}
public function startGame():void {
//positions flyer in middle of the stage
flyer.x = stage.stageWidth*.5;
fyler.y = stage.stageHeight*.5;
addChild(flyer);
}
}
}
This code works if I comment out the two lines where I position the flyer, but I don't want the flyer to be in the upper left corner so I definitely need the positioning statements. (flyer.x = stage.stageWidth*.5). With those statements, the following error occurs: "Access of possibly unidentified flyer through a reference with static type Main." (Main is the name of my .as file).
I looked up this error on google and it's usually associated with having the wrong instance name. So just to clarify the name of the symbol is Flyer, of the Flyer class. As you can see from the code I named the variable flyer. (Lowercase.) I don't understand how flyer could be unidentified when the code works perfectly without the positioning statement!
I would greatly appreciate anyone who could help me figure this problem out. I'm really pressed for time and I've already sunk hours into this error. Pleeeease help and I will be forever grateful! ![]()
In case it helps, here is a link to the tutorial: Flash Actionscript 3 for Games: Tutorial 9 - The Display List - YouTube