Solved

Pass Var To onPress Event

Posted on 2009-04-04
1
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flash movie or gif/animation? 3 945
Flash player 17 install script .bat or .vbs 9 579
Cannot install Adove Flash player on Windows 2012R2 6 105
File conversion question 5 133
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

730 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