Get with the times... Cor, first you're talking bout Director, then I hear 
you're still using MX... Tsk...  You're obviously not on the forefront of 
technology, huh? ;-)

Lee

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Danny Kodicek
Sent: 30 March 2006 09:46
To: Flashcoders mailing list
Subject: Re: [Flashcoders] Radiobutton - Dispatch event on code selected?

Crap, I keep forgetting about Dispatchers. Apologies - been coding in MX too 
long.

Danny

----- Original Message ----- 
From: "Aaron Smith" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, March 30, 2006 9:40 AM
Subject: Re: [Flashcoders] Radiobutton - Dispatch event on code selected?


Sure its possible!!!

Marcelo,

here is a solution:

put two radio buttons on the stage and call it rb1 / rb2. then in the
actions layer put:

import mx.controls.RadioButton;
import mx.utils.Delegate;
import mx.events.EventDispatcher;

var dispatchEvent:Function;
EventDispatcher.initialize(this);

//create prototype reference for RadioButton
var osv = _global.mx.controls.RadioButton.prototype;

//hold onto the old setSelected method ( The intrinsic set Selected
method is in SimpleButton, RadioButton inherits from that. the set
method simply calls setSelected.  )
osv.oldSetSelected = osv.setSelected;
osv.oldOnRelease = osv.onRelease;

//overwrite onrelease to deal with multiple events being dispatched.
osv.onRelease = function():Void
{
    this['wasReleased'] = true;
    this.oldOnRelease.apply(this,[]);
}

//overwrite the old method with new method.
osv.setSelected = function(val:Boolean):Void
{
    if( !this['wasReleased'] )
    {
        if( val == true )
        {
            this.dispatchEvent( { type:'codeSelected' } );
            this.oldSetSelected.apply( this,[ true ] );
        }
    }
    else
    {
        this.oldSetSelected.apply( this,[ true ] );
    }
    this['wasReleased'] = false;
}

//add listener to radio button.
rb1.addEventListener('codeSelected', Delegate.create(this,
handleCodeSelect));
rb1.addEventListener('click', Delegate.create(this, handleClick));

//handle code selected event
function handleCodeSelect():Void
{
    trace("codeSelected");
}

//handle click event
function handleClick():Void
{
    trace("CLICK");
}

//set an interval to do some testing on the codeSelected event
tmpInt = setInterval(setSel,1000,true);

//set the selected property
function setSel():Void
{
    //trigger the event
    rb1.selected = true;
}



test that out.. you'll see that for testing i just set an interval to
change the selected property to true.. the event gets dispatched every
time the selected property is set to true.  Also worth mentioning you
have to update the onRelease method to deal with multiple events being
dispatched. Also don't name the codeSelected event as click, as that is
not whats happening and would cause confusion.

rb2 is never used in this example.. just use that to click back and
forth between... also try commenting out the interval just for more
testing.. you'll see that just the click event fires..

smith




Danny Kodicek wrote:

>
> >It´s possible to make the radio button dispatch the "click" event if i
> select it by code?
>
> Not directly, but you could add something like this (I haven't used the rb 
> component for a while, but I think this would work
>
> radioButton.autoClick=function() {
> this.selected=true
> linkType_cml.setType()
> }
>
> Then to select the radio button you just call radioButton.autoClick(), and 
> your event should be dispatched.
>
> Danny
> _______________________________________________
> 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
>
>
>
_______________________________________________
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 

_______________________________________________
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
_______________________________________________
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