mardi 29 septembre 2015

Actionscript 3.0 How do i define objects from addChild?

So basically I wanted a boy to eat up some mushrooms that was generated using addChild. and i made a hittest for it. But i had an error 1120 of undefined property. how can I slove this? any help would be much appreciated.

heres my code.

    var timer:Timer = new Timer(1000,10);
timer.addEventListener(TimerEvent.TIMER, addTarget);

var score:int = 0;

function addTarget(e:TimerEvent)
    var posX = Math.random()*860;
    var posY = Math.random()*500;

    var mushroom:Mushroom = new Mushroom();

    mushroom.x = posX;
    mushroom.y = posY;
    boy_mc.addEventListener(Event.ENTER_FRAME, scoring);

function scoring(e:Event)
    if (boy_mc.hitTestObject(mushroom))

    score = score + (MovieClip(e.currentTarget).point);

    score_txt.text = String(score);

----------------and heres my class file----------

    import flash.display.MovieClip;

    public class Mushroom extends MovieClip
        private var size:Number;

        public var point:int;

        public var mushroom:int;

        public function Mushroom() 

            // constructor code
            size = (Math.random()*100)+20;
            this.width = size;
            this.height = size;

            point = Math.random()*10;



Aucun commentaire:

Enregistrer un commentaire