Itai Asseo wrote:
Hi - I am relatively new to Classes and OOP, and have come across a strange problem... I have a function in a class that creates dynamic buttons (xml driven). But when I try to actually use the buttons (ala 'onPress = function()') to fire up a different function within the class, it just won't work. it's like I'm outside the class now, and back to the main timeline.

Before you suggest me to use the Delegate class, I've already done that. It works, but the problem is that I have an unspecified amount of buttons (could be 10, could be 400) -- and each needs to pass a parameter, or variable to keep score. The Delegate class wouldn't let me pass any other variables other than which object is passing the onPress function, and which function to refer it to...

so I'm at a loss. if someone has a solution I would greatly appreciate it.

One way is to create a MyButton clip in the library and attach a class to it. Something like:

import mx.utils.Delegate;

class MyButton extends MovieClip {
        public var answer:String;
        
        public function dispatchEvent() {};
        public function addEventListener() {};
        public function removeEventListener() {};
        
        function MyButton() {
                super();

                mx.events.EventDispatcher.initialize(this);
                
                onRelease       = Delegate.create(this, release);
        }
        
        private function release():Void {
                dispatchEvent({target: this, type: "release", answer: answer});
        }
}

Then when you create the buttons:

//this is what the onRelease calls
function myButtonRelease(o:Object):Void {
        trace(o.answer);
}

//loop stuff
var myButton = theTarget.attachMovie("MyButton", "myButton" + n, theTarget.getNextHighestDepth()+n);
myButton.answer = "foo";
myButton.addEventListener("release", Delegate.create(this, myButtonRelease));

-Ricky
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to