Forums

ForumsProgramming Forum

Variable isn't working.

Thread Locked

Posted May 17, '11 at 3:38pm

Xinito

Xinito

108 posts

I just bought Flash and i'm trying some stuff in Flash building a Game in as2 but if I make a object that needs to add 5 points in the variable it doesnt go to 5 and it's stuck on 0 the whole time. Is it true that variables in as2 dont work for flash CS5?

 

Posted May 17, '11 at 5:31pm

Xinito

Xinito

108 posts

I did in the first frame

good = 100;
bad = 50;

and I made some dynamic text and did var: good and bad. When I test the movie they wont show up..

 

Posted May 17, '11 at 6:26pm

Darkroot

Darkroot

2,549 posts

I'm not really sure what you're talking about as2 doesn't require you to declare variable type as in as3.

For as2 you can get away with

var greeting = "Hello, world!" or even
greeting = "Hello, world!"

with as3 you can't you have to be more explicit

var greeting:String = "Hello, world!" but you can get away with
var greeting = "Hello, world!"

but if I make a object that needs to add 5 points in the variable it doesnt go to 5

Object is something entirely different in programming, careful with your word choice.

Is it true that variables in as2 dont work for flash CS5?

Yeah they work but you have to work in an as2 document and not an as3 document, if you want to write as2.

and I made some dynamic text and did var: good and bad. When I test the movie they wont show up..

Not sure you probably set up the textbox wrongly. Why don't you use trace(good); instead of displaying them anyway?

 

Posted May 17, '11 at 11:24pm

arobegamr

arobegamr

120 posts

If I read this correctly, you are referring to entering good and bad into the var field within the dynamic text properties box.

However, it is possible to have the text box display a variable through as2.

For example, you could place a dynamic text box and give it the instance name score_txt

You could have the text box update automatically with each frame, by typing the following into the actions window of the main stage:

score = 0
onEnterFrame = function (){
score_txt.text = score
}

Or, you could have the text box update every time the variable is changed.  You could create a movie clip with the instance name "coin_mc" Then type this one the main stage:

coin_mc.onPress = function (){
_root.score += 5
_root.score_txt.text=_root.score
}

If you choose to use the first option, simply remove the "_root.score_txt.text=_root.score" from the second, but use the rest.

I hope this helps to solve your problem

 

Posted May 18, '11 at 6:06am

Xinito

Xinito

108 posts

@Darkroot, ofc I worked in a AS2 file if I want to script with AS2,

Thanks for the information guys, i will try it.

 

Posted May 19, '11 at 3:19am

Xinito

Xinito

108 posts

@arobegamr Thanks so much, it works! now I can continue my rpg :D.

 

Posted May 19, '11 at 5:48pm

Xinito

Xinito

108 posts

arobegamr, it works perfectly but now I want that the coin disappear if I clicked on it, is this possible?

 

Posted May 19, '11 at 6:21pm

Darkroot

Darkroot

2,549 posts

Either make it go to the next empty frame in the timeline of the coin movieclip (if you are using one). Or just _root.coin.removeMovieClip(); or something similar, not 100% sure how it works in as2.

 

Posted May 19, '11 at 6:25pm

Xinito

Xinito

108 posts

I tryed that but fixed it with unloadMovie(this);

But I did this script to the coin:

onClipEvent (enterFrame) {
    if (_root.char.hitTest(this))
    {
        _root.score += 5;
        _root.vcam.score_txt.text = _root.score;
        unloadMovie(this);
    }
}

And I made a few more coins but if I hit one I get like 50 score because there 10 coins on my map, how can I fix that I only get 5 score and not all the scores once?

 

Posted May 25, '11 at 4:55pm

Xinito

Xinito

108 posts

Anyone can solve this probleme?