View Full Version : auto trigger button event
stii
March 12th, 2009, 01:42 AM
Hi guys,
i have a question, back in AS2 era,
if i have an MC on the stage with function as below
mc.onRelease = function() {
trace("RELEASED");
};
i can actually add in another line
mc.onRelease()
which will trigger my button event without me actually clicking on it.
I was wondering how can i achieve the same effect in as3?
because i am building a website, and i want the 1st button to trigger itself after it is
created on stage.
any idea guys?
thanks in advance
regards,
Edwin
Anogar
March 12th, 2009, 01:59 AM
Well, you can just call whatever method you have attached to your event listener.
myButton.addEventListener(MouseEvent.CLICK, onClick);
onClick();
function onClick(e:Event = null):void
{
trace("RELEASED");
}
BenBart
March 12th, 2009, 02:30 AM
ActionScript Code:
myButton.addEventListener(MouseEvent.CLICK, onClick);
onClick(e:MouseEvent){
trace("RELEASED");
}
myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
stii
March 12th, 2009, 02:32 AM
Well, you can just call whatever method you have attached to your event listener.
myButton.addEventListener(MouseEvent.CLICK, onClick);
onClick();
function onClick(e:Event = null):void
{
trace("RELEASED");
}
hi Anogar,
Thanks for your reply.
never thought of giving the event a default null value. :)
but i still have another question
for example if
myButton.addEventListener(MouseEvent.CLICK, onClick);
myButton.something = "something else"
function onClick(e:Event = null):void
{
trace(e.target.something);
}
do i have a way of getting around this? can i retrieve the value of "something" if i don't have the event ?
thanks in advance!!!!!
regards,
Edwin
stii
March 12th, 2009, 02:42 AM
ActionScript Code:
myButton.addEventListener(MouseEvent.CLICK, onClick);
onClick(e:MouseEvent){
trace("RELEASED");
}
myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
Hi benbart,
you're the man!!! you solved my problem !!!!!!!!!!!!!!!!
thanks thanks
cheers,
Edwin
stii
March 12th, 2009, 02:45 AM
final code:
myButton.addEventListener(MouseEvent.CLICK, onClick);
myButton.something = "something else";
function onClick(e:Event = null):void {
trace(e.target.something)
}
myButton.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
this will give me a trace of "something else"
just like if i click the button :)
thanks guys
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.