Solved

Pass Var To onPress Event

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now