Introduction to the signals Framework (ii) Advanced events __ Frame

Source: Internet
Author: User

Note: This article refers to a introduction to AS3 signals written, but not translated, there is an increase in the deletion. Part I: Introduction to the signals Framework (i) Basic Usage Part III: Introduction to the signals Framework (iii) native events

Perhaps you are now reminded of the benefits of AS3 built-in event framework, and you want to use Currenttarget. or want to support bubbling. Ok,signals can also satisfy your changeable heart ... (seems to be my own changeable ˇ^ˇ) Advanced Events

You can use Deluxesignal to achieve more advanced event delivery. Or based on the example of the alarm clock to modify the original alarmclock in the signal to deluxsignal:

[Alarmclock.as]? View Code ACTIONSCRIPT

1
2
3
4 5 6 7 8
9
ten
-one 12
function AlarmClock ()
{
    //passes itself as a reference to deluxesignal, while increasing genericevent's delivery
    new deluxesignal (this, GenericEvent, Date);
var alarm:deluxesignal;
function ring (): void
{
    Alarm.dispatch (newnew Date ());
}

Modify the processor function in the wakeup.as to allow it to accept the 2 parameters passed.

[Wakeup.as]? View Code ACTIONSCRIPT

1
2
3
4
5
6 7
function handler_ring ($evt: genericevent, $date:D ate): void
{
    trace (' Currenttarget: ', $ Evt.currenttarget);
    Trace (' Target: ', $evt. Target);
    Trace (' Signal: ', $evt. signal);
    Trace (' Get up ... Also do not look at the time: ' + $date. toString ());

The genericevent that appear here, not inherit from Flash.events.Event, but realize signals own ievent interface, have nothing to do with AS3 event mechanism. Take a name that looks like a brother, is to facilitate everyone to understand it. The Currenttarget and target attributes provided by it are also provided by the ievent itself.

After you run the modified example, you can see the following output:

[Trace] Currenttarget: [Object AlarmClock]
[Trace] Target: [Object AlarmClock]
[Trace] Signal: [Object deluxesignal]
[Trace] got up ... Also do not look at the time: Mon 17:07:16 gmt+0800 2012

Now, is it possible to "do whatever you want" to Currenttarget? Bubbling Events

Signals is as bubbling as it is, and does not depend on the AS3 event mechanism. Of course, the objects that send and receive bubbling events must be in the display list.

In order for AlarmClock to be added to the display list, we let AlarmClock inherit sprite. Throwing bubbling events is very simple, simply by passing the true argument while instantiating the genericevent. Look at the modified part of the AlarmClock class:

[Alarmclock.as]? View Code ACTIONSCRIPT

1
2
3
4
5
6 7
class AlarmClock extends Sprite
{
    function ring (): void
    {
        alarm.dispatch (new GenericEvent (truenew Date ());
    }

The class that receives the event must implement the Ibubbleeventhandler interface to handle the bubbling event in oneventbubbled. Also, add the \_alarm instance to the display list.

To facilitate viewing of the bubbling effect, you can comment out the addonce line and receive only bubbling events.

[Wakeup.as]? View Code ACTIONSCRIPT

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  
public  class  Wakeup extends Sprite implements Ibubbleeventhandler {public  function  Wakeup () {_alarm =  new  Alarmclo
        CK ();
        AddChild (_alarm);
        _alarm.alarm.addonce (handler_ring);
    _alarm.ring (); }   Public  function  oneventbubbled ($evt: IEvent 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.