The problem is with this code- the onRelease function is a method of
the btn movieclip... so it doesn't have access to the dispatchEvent
function.
btn.onRelease = function() {
trace('dispatching event');
dispatchEvent({type:'click', target:this, message:btn+' was
clicked'});
};
You could just do something like this instead if you want a quick
local function:
var btnRelease = function () { dispatchEvent({type:'click',
target:this, message:btn+' was clicked'}); }
btn.onRelease = Delegate.create(this, btnRelease);
Delegate saves the day again...
-Danro
On Sep 27, 2006, at 8:30 AM, vic wrote:
John, I think so but what I am trying to do it set up a BtnFunc
Class that I can pass an argument to in order to set up the
functionality of the button (argument bein the button instance
name). I am pretty close I have this so far:
FLA (with btnOnStage on stage):
import mx.utils.Delegate;
function handleEvent(eventObj) {
trace('handleConstruct')
trace(eventObj.target);
trace(eventObj.type);
trace(eventObj.message);
trace(eventObj.time);
}
var myBtnClass = new BtnFunc(0, btnOnStage);
myBtnClass.addEventListener('click', Delegate.create(this,
handleEvent));
----------------------
Class (BtnFunc.as):
import mx.events.EventDispatcher;
import mx.utils.Delegate;
class BtnFunc {
var addEventListener:Function;
var removeEventListener:Function;
var dispatchEvent:Function;
function BtnFunc(id, btn) {
EventDispatcher.initialize(this);
btn.onRelease = function() {
trace('dispatching event');
dispatchEvent({type:'click', target:this, message:btn+' was
clicked'});
};
}
}
It is firing off the event perfectly but my listener is not getting
it and thus not running the handleEvent func. What's the prob?
_______________________________________________
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