Created
August 16, 2012 12:57
-
-
Save vrobel/3369930 to your computer and use it in GitHub Desktop.
Signal that notifies when target DisplayObject lands on stage dispatching target DisplayObject and Stage objets. Adding listener dispatches immidiately when target is already on stage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created with IntelliJ IDEA. | |
* User: wrobel221 | |
* Date: 16.08.12 | |
* Time: 14:35 | |
* To change this template use File | Settings | File Templates. | |
*/ | |
package com.blackmoondev.signals.native | |
{ | |
import flash.display.DisplayObject; | |
import flash.events.Event; | |
import org.osflash.signals.ISlot; | |
import org.osflash.signals.natives.NativeMappedSignal; | |
public class StageReadySignal extends NativeMappedSignal | |
{ | |
public function StageReadySignal( target : DisplayObject, listener : Function = null ) { | |
super( target, Event.ADDED_TO_STAGE, Event ); | |
addOnce( listener ); | |
} | |
override protected function mapEvent( eventFromTarget : Event ) : Object { | |
return getValueObjects() | |
} | |
private function getValueObjects() : Array { | |
return [_target, (_target as DisplayObject).stage]; | |
} | |
private function hasStage() : Boolean { | |
return (_target as DisplayObject).stage != null; | |
} | |
override public function mapTo( ...rest ) : NativeMappedSignal { | |
throw new Error( 'You can\'t mapTo in this class. I handle it by myself' ); | |
} | |
override protected function registerListenerWithPriority( listener : Function, once : Boolean = false, priority : int = 0 ) : ISlot { | |
var slot : ISlot = super.registerListenerWithPriority( listener, once, priority ); | |
if ( hasStage() ) { | |
slot.execute( getValueObjects() ); | |
} | |
return slot; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment