dimanche 19 mars 2017

error #1009 addChld() as3 with loop

when i try to addChild my class it says "Cannot access a property or method of a null object reference. at class_obj() at Main()" error #1009

i need to know how to have a class that has a gameloop for testing things like collision and stuff please help!

and if i dont have eventlistener enter frame on the object ir works but i need the listener for the loop.

Main class

package
{
    import flash.display.MovieClip;
    import flash.events.Event;

    public class Main extends MovieClip
    {
        var mc:class_obj;

        public function Main()
        {
            //constructor
            mc = new class_obj();
            addChild(mc);
        }
    }
}

object class

package  
{

    import flash.display.MovieClip;
    import flash.events.Event;

    public class class_obj extends MovieClip 
    {

        public function class_obj() 
        {
            // constructor code
            stage.addEventListener(Event.ENTER_FRAME, loop);
        }
        public function loop(e:Event)
        {
            trace("LOOPED CLASS");
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire