Solved

Pass Var To onPress Event

Posted on 2009-04-04
1
226 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

630 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