A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: using variable in dynamic text?

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    9

    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,834
    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~

  4. #4
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    i know a lot of time passed between my original post but i used your tip and it doesnt work! no text shows up at all. which is weird because i was able to make dialogue text work but not this. the thext has the same name as in the code and ust nothing shows up. maybe im using it on the wrong layer? i have it on my main layer where all my actionscripts are, should i use it on the textbox layer?

  5. #5
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    @gogetax1 sorry idk how to notify people here :L

  6. #6
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    it says root i undefined. the text is dynamic but i just didnt know how to add the variable

  7. #7
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    There are 2 ways to handle this with as3. 1 is to use relative paths from the object. You'll have to use parent and so forth. You could also create a global variable root and assign the stage as that.
    .

  8. #8
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    Quote Originally Posted by swak View Post
    There are 2 ways to handle this with as3. 1 is to use relative paths from the object. You'll have to use parent and so forth. You could also create a global variable root and assign the stage as that.
    sorry but i dont understand any of this. i just started working this from tutorials.....

  9. #9
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    sorry but i dont understand any of this
    sorry but you will have to. you can't fly a Boeing before spending few years in a pilot school.
    who is this? a word of friendly advice: FFS stop using AS2

  10. #10
    Junior Member
    Join Date
    Apr 2019
    Posts
    9
    Quote Originally Posted by realMakc View Post
    sorry but you will have to. you can't fly a Boeing before spending few years in a pilot school.
    you are joking right? this is the most useless and stupidly condescending thing ive heard in a long time. really on the level of 14 year old.
    i am not flying a boeing, i am using the dynamic text option which is incredibly simple for a beginner and having some trouble with the execution.
    ''spend a few years in a pilot school'' jesus, im a doing a little simple game so that i can learn the basic and asking about simple things on a forum made for that, am i supposed to buy out an advanced programming course just because i want to learn the foundations?
    dont want to help, dont bother answering

  11. #11
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    Path deals with anything that can contain code. If you put code in anything but a layer then you will have to deal with it. Say you create an object and put code on it. Then you want to have that code refer to another object or textfield then you'd have to use this.parent in that code. Root use to refer to the base stage where everything is animated. With as3 you'd have to set that up. So just focus on relative paths. This would be why root was undefined, it was removed with the code version switch from 2.0 to 3.0. Now you either have to use relative paths or create a global variable.

    Since you don't seem to be placing the code on any object then you should make the target textfield into a dynamic textfield. You'll find this option in the properties window. You'll need to give the textfield a name to refer to it. You'll see a field to do this in the properties window after changing it from a static to dynamic text field. If you name it: TXT_MyText then use gogetax1's code:
    Code:
    if(linkMc.hitBoxMc.hitTestObject(overworldMc.starM c1))
    {
    star += 1;
    TXT_MyText.text = "Total Stars: "+String(star);
    overworldMc.starMc1.alpha = 0;
    }
    To further explain paths there are some examples here. overwoldMC would be an object and starMC1 would also be an object. In the code above it shows the address needed for the code to find starMc1. If you place the textfield in the same location as starMc1 then the path for it would be overworldMc.TXT_MyText.
    Last edited by swak; 05-06-2019 at 09:29 PM.
    .

  12. #12
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    am i supposed to buy out an advanced programming course just because i want to learn the foundations?
    pretty much so. you guys ask for a help on forums, get helped, then come back a week later with another question having learned nothing. you do need programming course.
    who is this? a word of friendly advice: FFS stop using AS2

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