Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-06-2005, 08:51 PM   #1
jabberwo
Registered User
 
Join Date: Dec 2004
Posts: 2
Default adding custom properties to a button

I'm feeling like an idiot here. Please help me.

I'm building a group of buttons (array or not, doesn't matter to me,) and I need a way for each button to report its own index. I've done this before with movie clip objects, by simply adding an id property to the movie clip. I set the index when I created the movie clip, and then I could retrieve it from the button's release event. However, the same technique does not seem to work with buttons. When I add a custom property to the button object, it's reported as undefined.

Here's my latest attempt (I've abandoned arrays for the virtual array form at this point)

HTML Code:
//code in frame
init();

function init(){
  //set up buttons
  //set up sounds
  //Button.prototype.index = 0;
  theSound = new Sound();

  for (i = 0; i <= 5; i++){
    btnName = "btn_" + i;
    btnDepth = 100 + i;
    _root.attachMovie("Button", btnName, btnDepth);
    theButton = eval(btnName);
    theButton.label = btnName;
    theButton._x = 50
    theButton._y = i * 30;
    theButton.id = i;
    theButton.soundName = "audio/ - Track0" + i + ".mp3";
    theButton.onRelease = function(){
      trace(_this.id);
      trace(_this.soundName);
      //theSound.loadSound(soundName, true);
      //theSound.start();
    } // end button release
  } // end for loop  
} // end init
Both soundName and id are reported as undefined from within the event handler. Similar code works flawlessly with movie clips.

Please make me feel like an idiot! Tell me I'm missing something simple.

I suspect the button object simply doesn't allow these basic properties.
I think I can handle actionscript 2.0, but I don't really want to go there for this project.

Thanks in advance!

-Andy

Last edited by jabberwo; 01-06-2005 at 08:55 PM.
jabberwo is offline   Reply With Quote
Old 01-06-2005, 10:19 PM   #2
Xeef
Off-Line
 
Xeef's Avatar
 
Join Date: Aug 2004
Location: Ibiza/Spain language :Hungarian/German/ abit English
Posts: 6,539
Default

_this ?????

PHP Code:
this 
__________________

test your self -->http://www.actionscript.org/forums/s...86&postcount=8
Xeef is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:52 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.