actionscript 3 - as3 Error 1009 at Coin1/coin1go(), i am trying to get an enemy to drop a coin -


so enemy drop coin not properties of coin( if hits player gives him +5 coins)

the coin removed if hits bottom of stage, if player dies or if player hits it. sadly, not work.

but work if place coin on stage before start game, gets properties, must moment gets added stage not linked coding or something..... , right now.

this .as file coin:

package {

import flash.display.movieclip; import flash.events.event; public class coin1 extends movieclip {     private var _root:object;     private var speed:int = 0;      public function coin1()     {     addeventlistener(event.enter_frame, speed1);     addeventlistener(event.added, beginclass);     addeventlistener(event.enter_frame, coin1go);     }     private function beginclass(event:event):void     {         _root = movieclip(root);     }      private function speed1(event:event):void     {         y +=  speed;     }          private function coin1go(event:event):void         {         if (this.y > stage.stageheight)         {             removeeventlistener(event.enter_frame, coin1go);             _root.removechild(this);         }         if (hittestobject(_root.player_mc))         {             _root.coin +=  1;             removeeventlistener(event.enter_frame, coin1go);             _root.removechild(this);          }         if (_root.playerhealth <= 1)         {             removeeventlistener(event.enter_frame, coin1go);             _root.removechild(this);          }     } } 

}

this part gets added stage:

    if (enemy2health <= 0)     {         removeeventlistener(event.enter_frame, eframe);         _root.score +=  _root.enemy2score * _root.scoremultiplyer;         stage.addchild(newexplosionsmall)         newexplosionsmall.x = this.x;         newexplosionsmall.y = this.y;         stage.addchild(newcoin1)         newcoin1.x = this.x;         newcoin1.y = this.y; 

ass can see there addchild explosion wich works fine may jus because nothing else appear , remove itself.

so long story short: enemy drops coin nothing , floats bottom of screen , constant stream of 1009 errors. know how fix this?

you should add enterframe listener after receiving valid stage reference, appears when event.added_to_stage event received. because enterframe listener refers stage.

public function coin1() {     addeventlistener(event.enter_frame, speed1);     addeventlistener(event.added_to_stage, beginclass); } private function beginclass(event:event):void {     _root = movieclip(root);     addeventlistener(event.enter_frame, coin1go); } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -