Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pass Var To onPress Event

Posted on 2009-04-04
1
Medium Priority
?
229 Views
Last Modified: 2013-11-11
Experts - I am looping through an array of movie clip names in actionscript 2.0 and need to figure out a way to pass a var to the onPress function. I'm dealing with a scope issue, but am not sure how to fix it.

I have the following code on the first frame of my timeline. The issue is, when the onPress event is fired, counties[i] is undefined. Is there a way I can pass the array variable into the onPress event function without loosing scope?

Thank you for your help!

~ C
counties = testVar1.split(',');
 
for (var i = 0; i < counties.length; i++)
{
	var o = eval(counties[i]);
	o.stop();
	o._alpha = 70;
	
	o.onPress = function()
	{
		getURL("#" + counties[i]);
	}
}

Open in new window

0
Comment
Question by:clickclickbang
1 Comment
 
LVL 1

Accepted Solution

by:
clickclickbang earned 0 total points
ID: 24068116
I was able to fix this myself with relative ease. Just declare a var before the function and then call it in the function.
counties = testVar1.split(',');
 
for (var i = 0; i < counties.length; i++)
{
        var o = eval(counties[i]);
        o.stop();
        o._alpha = 70;
        o.varToCallInsideFunction = counties[i];
        o.onPress = function()
        {
                getURL("#" + this.varToCallInsideFunction);
        }
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question