dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: using variable in dynamic text?

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    1

    using variable in dynamic text?

    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 changed it to

    var star:Number = 0;

    if(linkMc.hitBoxMc.hitTestObject(overworldMc.starM c1))
    {
    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/act...ings.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?

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,780
    Add something like this:
    _root.starsTxt.text = "Star: "+star;
    You have make the textfield dynamic and give it the name starsTxt for this to apply.
    .

  3. #3
    i'm the Best of doing nothing
    Join Date
    Apr 2019
    Posts
    15
    create a text inside your stage, make sure its "Dynamic Text", give it a name such as TXT_MyText, add embed fonts into your project (all of those settings done when you click once on your text)
    now just call:

    if(linkMc.hitBoxMc.hitTestObject(overworldMc.starM c1))
    {
    star += 1;
    TXT_MyText.text = "Total Stars: "+String(star);
    overworldMc.starMc1.alpha = 0;
    }

    since my text accepts strings only, and our "star" varible is a value, we have to change it to String using the String(star) command.

    the rest is pretty much understandable.

    also, i've made the other day a video on youtube how to create simple buttons, it also involves the Text messages. take a look at:


    hope this will help~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center