Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating Your Own Property for a MovieClip in AS3

Participant ,
Jun 16, 2008 Jun 16, 2008
Hello Community!

Starting to get my AS3 feet wet and have not been able to figure out a tried and true method I usually use for handling a series of similarly named buttons.

Scenario: I have a series of, say, 10 buttons (actually MovieClips that behave as buttons) that are named [selector0, selector1, ..., selector9] which all call the same function but pass a different variable "ivar" that is the same value of the number part of the name of that button. For example, if I click on the "selector3" button the "ivar = 3" is passed to the function, etc..

This is the AS2 code that I have used faithfully in this scenario which enable me to write a few line of codes to control all 10 of the buttons at the same time instead of having to write 10 seperate ".onRelease = function..." is as follows (under //OLD SCHOOL):

Now, I have tried to make this scenario work in AS3 with the following (under //NEWSCHOOL): but it does not work. I think that the problem is centered on the fact that I only pass the MouseEvent to the function but not the ivar variable. I have tried to pass two arguments to the function, but with strange error messages.

I suspect that since AS3 is more robust that there is a super elegant way to solve the problem that I am having: controlling a large series of similarly named, indexed buttons with one loop instead of needing to write out separate code for each button.

Any feedback would be greatly appreciated.

-john
TOPICS
ActionScript
315
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 16, 2008 Jun 16, 2008
In the new selector function:

imgIndex = e.target.ivar;
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 16, 2008 Jun 16, 2008
Brilliant -- works as desired! Thanks NedWebs!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 16, 2008 Jun 16, 2008
LATEST
If I wanted to use buttons (flash.display.SimpleButton) instead of using MovieClips as buttons in the previous example, is there some property of a SimpleButton that I could place that "ivar" value into?

If I apply the technique above on a series of simple buttons, instead of MovieClips, I get the error: "Cannot create property ivar on flash.display.SimpleButton."

-john
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines