0

Im trying out adobe animate for school and until now ive been following a cool rpg game tutorial. but the tutorial ended quicky and now im left on my own browsing the internet. i wanted to add a little star collector feature but the tutorial i found is for flash and i dont know how to use it.

their code is pretty much

money = 0;

onClipEvent (enterFrame) {
if (_root.move_mc.hitTest (this)) {
_root.money++;
this._x = -50;
this._y = -50;
}
}

and i hanged it to

     var star:Number = 0;

    if(linkMc.hitBoxMc.hitTestObject(overworldMc.starMc1))
    {
        star += 1;
        overworldMc.starMc1.alpha = 0;
    }

and it works but now i need to figure out a way to set up a text n the corner telling you how many stars you have.

[link to their image] (https://www.kirupa.com/developer/actionscript/images/textBox_settings.JPG)((((i cant post images yet as i dont have enough points)))) but my version of adobe animate doesnt seem to have the var option! so how do i set up the text?

Glithch
  • 1
  • 2
  • The **onClipEvent** instruction is not AS3, it is AS1, thus it is incompatible with **hitTestObject** which is AS3. – Organis Apr 15 '19 at 15:43
  • @Organis sorry but i dont understand what you mean. im not using the onClipEvent. as i said i changed it into the script lower. my issue is with setting up the dynami text for the text box counting the collected stars. check out the link – Glithch Apr 15 '19 at 15:55
  • 2
    **money_box.text = star + "";** – Organis Apr 15 '19 at 16:15
  • https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html – ugotopia123 Apr 15 '19 at 16:21
  • @organis i dont think you read my question at all – Glithch May 02 '19 at 10:10
  • @ugotopia123 thanks i looked through this before asking this question it doesnt answer my question at all. didnt expect so many people here to be so rude and unhelpful – Glithch May 02 '19 at 10:11

1 Answers1

0

Try some logic like below. The code is untested, but should be useful to you towards a working solution:

var star :int = 0;

//# create an *enterFrame* function for multiple stars
overworldMc.starMc1.addEventListener( Event.ENTER_FRAME, myClipEvent ); 
overworldMc.starMc2.addEventListener( Event.ENTER_FRAME, myClipEvent );
overworldMc.starMc3.addEventListener( Event.ENTER_FRAME, myClipEvent );

function myClipEvent( myEvt:Event ) :void
{
    //# or... myEvt.currentTarget
    if(myEvt.target.hitTestObject(linkMc.hitBoxMc))
    {
        star += 1; //can be... star++;

        myEvt.target.alpha = 0; //# also test replacing *target* with *currentTarget*

        //# use String( xxx ) to cast Numeric data type into a Text data type
        money_box.text = String(star) + " " + "Stars..."; 
    }
}
VC.One
  • 14,790
  • 4
  • 25
  • 57
  • it says my clip event is undefined – Glithch May 02 '19 at 10:08
  • I've just tested and it worked fine for me. Used `stage.addEventListener( Event.ENTER_FRAME, myClipEvent );`... You could try adding at the top of your code: `import flash.events.*;` and maybe change from `function myClipEvent` into this `public function myClipEvent`... – VC.One May 02 '19 at 20:15