PDA

View Full Version : Forcing On Events


Stampy
09-14-2006, 12:25 AM
I'm pretty new to actionscript, and its rather odd coming from a c++ background. What i was wondering, ( i've poked around the net, and the tutorials up here to see if i could find anything, without much luck ) was if i were to have a comboBox which had for example an on(Change) event; could that function be forced to be invoked, from say a button press?

The issue i have at hand is that i am having to put a lot of nasty duplicated code in crazy switch statements and such as i can't fathom a way of invoking said function. And i can't declare functions inside objects such as a comboBox as far as i'm aware.

Any ideas? Thanks.

silentweed
09-14-2006, 12:46 AM
what exactly are u trying to do? if your looking for a way for two events to call the same function without duplication of the function here is an example using two movie clips with instance names mc1 and mc2.


mc1.onRelease = doStuff;
mc2.onRelease = doStuff;

function doStuff(){

trace("Hey you just clicked on the movieclip " + this);

}

senocular
09-14-2006, 12:51 AM
since combo box events utilize EventDispatcher, you'd have to use
myCombo.dispatchEvent({type:"change"});

Stampy
09-14-2006, 01:01 AM
Thanks for the quick reply. That's not what i'm after, but its kinda funky to know you can do that too..

Here's a completely oversimplified representation of something i'm after.


// In the first ComboBox
on(change)
{
trace( "this has been changed" );
}



// In the second ComboBox
on(change)
{
// Make the first ComboBox call its change code here
// do other stuff too
}


I guess i could just have the code floating around in some external file, but i like to have all the code inside the object its meant to be. Is there anyway of calling that onChange() without actually clicking the mouse on it and changing it?

EDIT - aha! Events eh? Thanks a lot, that's exactly what i was looking for. Thanks to you both for you time.