Solved

Dynamically Creating and Assigning a Handler for each Button

Posted on 2003-10-21
2
142 Views
Last Modified: 2010-04-03
Hi,

Well, here's my problem:

I am trying to dynamically create a list of movieclips with button in each. I want to assign each button a specific event handler for the onRelease, for example. The following code was produced:

      clip.readMore.btn.onRelease = function () {
            trace ("Clicked on Button#" + i);
      };

...where essentially "btn'' is the button. Now the problem is, whenever I click any button, I get the same value, which is the max value for i.

What I think is the problem is that Flash stores the code of the function as is without evaluating the symbol or variable i. Then, when the button is called, it fetches the value of i and uses it.

I want such a way that I can "inject" the value of the current i, knowing the this piece of code runs in a for-loop.

Thanks in advance
0
Comment
Question by:amotaz
[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
2 Comments
 
LVL 27

Accepted Solution

by:
negatyve earned 100 total points
ID: 9595538
you have to save the i variable as an button instance property. for example:

for(var i = 0; i < 20; i++){
      clip.readMore["btn" + i].ID = i;
      clip.readMore["btn" + i].onRelease = function ()
      {
            trace ("Clicked on Button#" + this.ID);
      };
};
0
 

Author Comment

by:amotaz
ID: 9661683
negatyve,

Thank you. Although that's not exactly what I wanted, but it worked.

Setting the button's .ID worked.

Thanks again.

I have another question that I have posted already. Please take a look at it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Firefox video player - embedded native versus VLC player 3 1,106
Flash doesn't load in Iphone and Ipad 22 497
how can i learn adobe flex step by step 4 125
flash professional 3 32
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…
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…
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…
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.

756 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