Solved

Dynamically Creating and Assigning a Handler for each Button

Posted on 2003-10-21
2
140 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
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.

813 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

11 Experts available now in Live!

Get 1:1 Help Now