Solved

Pass Var To onPress Event

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FlashBuilder allocate more memory using FlashBuilder.ini 18 266
video live streaming 1 123
System Center Configuration Manager 2012R2 7 86
You Tube Videos not playing 9 124
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,…
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 live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

809 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