PDA

View Full Version : Throw events manually


Damask
11-23-2005, 03:48 PM
Is there a way to throw events manually via ActionScript?

Here is my scenareo:
I have a combobox component.
I randomly (via ActionScript) select a value based on its contents.
I then need to throw events just as if the user did the change.

(or is there an easier way?)


Cheers,
Damask

terek
11-23-2005, 04:14 PM
Event handling in as is like calling functions.

You simply call the event like a function.

for example:



var x:Object = new Object();

x.onPush = function(times:Number){
trace("pushed");
}


// now, if you want to send a "push" event, you simply call:

x.onPush(10);

Damask
11-23-2005, 04:28 PM
That's what I thought, but it isn't working for me. :(

Here's what I have:
this.item_cbx.addEventListener("change", comboChanged);
function comboChanged(eventObj:Object) {
// does stuff
}

I can set the selectedIndex to a different value:
this.item_cbx.selectedIndex = 2;

That's fine, but it won't automatically fire the "change" event (as if the user interacted with the combobox).
I figure I need to fire it myself, but that means I need an 'event' object.
Trying to create an event object either fails or does not work.

Fails:
comboChanged({"change",this.item_cbx});

Does not work:
var obj:Object = new Object();
obj.type = "change";
obj.target = this.item_cbx;
comboChanged(obj);


Any idea why?

Damask
11-23-2005, 06:31 PM
Here's a simple example I built to illustrate the problem.

Anyone know what to do? I really need to find a solution to this :(