Reputation: 105
Can anyone can help me with this issue. I have no idea with this issue. Just keep getting this issue. Already try modify from this
function init(e:Event = null)
to function init()
or function init(e:Event)
Appreciated who can help me with this. If no issue on this, it should show food not my stage.
package {
import flash.display.MovieClip;
import flash.ui.Keyboard;
import flash.events.KeyboardEvent;
import flash.events.Event;
public class Main extends MovieClip {
var snake:Array;
var score:Number;
public function Main() {
// constructor code
if(stage)
addEventListener(Event.ADDED_TO_STAGE, init);
else
init();
}
function init(e:Event = null):void {
//initialize
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame(e:Event):void {
var food:Food = new Food();
this.addChild(food);
trace("food");
}
}
}
Upvotes: 1
Views: 496
Reputation: 6708
Your code is almost correct.
Replace if (stage)
to if (!stage)
.
If error still happens attach FLA.
Upvotes: 2