PDA

View Full Version : Simple Add-Too Variable


Cornbane
05-03-2010, 03:59 AM
Hey guys. I'm having an issue with a simple bit of code that seems too easy, but it just won't work for me. I couldn't find the solution in help or google within reasonable time so hopefully someone can toss me a solution quickly.

Here's a simple example of what I'm looking for:

I have a variable:
var myVar:String = "cheese";

When I click a button I want addition text added to that variable:
stage.addEventListener(MouseEvent.MOUSE_DOWN, yayIWasClicked);

function yayIWasClicked(e:MouseEvent):void {
myVar = myVar + "extratext";
}


The code there is what I thought would work, it did, but not how I wanted it to. What I want it to do is keep adding to the variable each time instead of just once.

Can anyone turn me in the right direction?

vinayak.kadam
05-03-2010, 12:33 PM
You code worked for me as you wanted it to. Check the attachment!

flashsourcecodes
05-03-2010, 12:48 PM
It has to work. The code you posted works.

sdfg
05-03-2010, 05:55 PM
If you are looping back through frame 1, then your myVar will get reassigned back to "cheese" each time.

Cornbane
05-03-2010, 07:10 PM
Thanks guys. I'd have kept searching the wrong spot long after without the feedback. The code was right and I found the problem. Variable was inside the main function too, was looking for the issue inside one of the external AS files. Basically whenever I activated the trigger it would reset the variable to the original state because it was inside the function too. Careless mistake.

lindan11
05-07-2010, 07:25 AM
Hi all, thanks all for this post!
------------
Koozie Questions (www.drinkoutloud.com/questions.html)