org.osmf.traits

# TraitEventDispatcher - AS3 OSMF

Package | org.osmf.traits
Class | public class TraitEventDispatcher
Inheritance | TraitEventDispatcher EventDispatcher Object
Subclasses | MediaPlayer

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

TraitEventDispatcher is a utility class that exposes a uniform interface for receiving trait events from a MediaElement. This class monitors the MediaElement for traits being added and removed, and dispatches any events that the MediaElement's traits dispatch, and for which the client has registered listeners.

View the examples

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | media : MediaElement The MediaElement which will be monitored, and whose trait events will be redispatched. | TraitEventDispatcher

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | TraitEventDispatcher() Constructor. | TraitEventDispatcher
|  | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event. | EventDispatcher
|  | dispatchEvent(event:Event):Boolean Dispatches an event into the event flow. | EventDispatcher
|  | hasEventListener(type:String):Boolean Checks whether the EventDispatcher object has any listeners registered for a specific type of event. | EventDispatcher
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void Removes a listener from the EventDispatcher object. | EventDispatcher
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object
|  | willTrigger(type:String):Boolean Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type. | EventDispatcher

Events
Click for more information on events
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | activate | [broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active. | EventDispatcher
|  | audioSwitchingChange | Dispatched when an alternative audio stream switch is requested, completed, or has failed. | TraitEventDispatcher
|  | autoSwitchChange | Dispatched when the autoSwitch property has changed. | TraitEventDispatcher
|  | bufferingChange | Dispatched when the buffering property has changed. | TraitEventDispatcher
|  | bufferTimeChange | Dispatched when the bufferTime property has changed. | TraitEventDispatcher
|  | bytesTotalChange | Dispatched when the bytesTotal property has changed. | TraitEventDispatcher
|  | canPauseChange | Dispatched when the canPause property has changed. | TraitEventDispatcher
|  | complete | Dispatched when the media has completed playback. | TraitEventDispatcher
|  | deactivate | [broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive. | EventDispatcher
|  | displayObjectChange | Dispatched when the displayObject property of the media has changed. | TraitEventDispatcher
|  | drmStateChange | Dispatched when the state of the DRMTrait has changed. | TraitEventDispatcher
|  | durationChange | Dispatched when the duration property of the media has changed. | TraitEventDispatcher
|  | isRecordingChange | Dispatched when the isRecording property has changed. | TraitEventDispatcher
|  | loadStateChange | Dispatched when the state of the LoadTrait has changed. | TraitEventDispatcher
|  | mediaSizeChange | Dispatched when the mediaWidth and/or mediaHeight property of the media has changed. | TraitEventDispatcher
|  | mutedChange | Dispatched when the muted property of the media has changed. | TraitEventDispatcher
|  | numAlternativeAudioStreamsChange | Dispatched when the number of alternative audio streams has changed. | TraitEventDispatcher
|  | numDynamicStreamsChange | Dispatched when the number of dynamic streams has changed. | TraitEventDispatcher
|  | panChange | Dispatched when the pan property of the media has changed. | TraitEventDispatcher
|  | playStateChange | Dispatched when the playing or paused property of the media has changed. | TraitEventDispatcher
|  | seekingChange | Dispatched when the seeking property of the media has changed. | TraitEventDispatcher
|  | switchingChange | Dispatched when a dynamic stream switch change occurs. | TraitEventDispatcher
|  | volumeChange | Dispatched when the volume property of the media has changed. | TraitEventDispatcher

Property Detail

### media

property

`media:MediaElement`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

The MediaElement which will be monitored, and whose trait events will be redispatched.

Implementation
`public function get media():MediaElement`
`public function set media(value:MediaElement):void`
Constructor Detail

### TraitEventDispatcher

()
Constructor

`public function TraitEventDispatcher()`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Constructor.

Event Detail

### audioSwitchingChange

Event

Event Object Type: `org.osmf.events.AlternativeAudioEvent`
property AlternativeAudioEvent.type = `org.osmf.events.AlternativeAudioEvent.AUDIO_SWITCHING_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.6

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when an alternative audio stream switch is requested, completed, or has failed.

Dispatched when the switching state of the alternative audio stream has changed. Usually for any successful switching operation, two AUDIO_SWITCHING_CHANGE events will be triggered. One when the switch operation starts ( the `switching` property will be set to `true` ) and one when the operation ends ( the `switching` property will be set to `false` ).

### autoSwitchChange

Event

Event Object Type: `org.osmf.events.DynamicStreamEvent`
property DynamicStreamEvent.type = `org.osmf.events.DynamicStreamEvent.AUTO_SWITCH_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `autoSwitch` property has changed.

The DynamicStreamEvent.AUTO_SWITCH_CHANGE constant defines the value of the type property of the event object for an autoSwitchChange event.

### bufferingChange

Event

Event Object Type: `org.osmf.events.BufferEvent`
property BufferEvent.type = `org.osmf.events.BufferEvent.BUFFERING_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `buffering` property has changed.

The BufferEvent.BUFFERING_CHANGE constant defines the value of the type property of the event object for a bufferingChange event.

### bufferTimeChange

Event

Event Object Type: `org.osmf.events.BufferEvent`
property BufferEvent.type = `org.osmf.events.BufferEvent.BUFFER_TIME_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `bufferTime` property has changed.

The BufferEvent.BUFFER_TIME_CHANGE constant defines the value of the type property of the event object for a bufferTimeChange event.

### bytesTotalChange

Event

Event Object Type: `org.osmf.events.LoadEvent`
property LoadEvent.type = `org.osmf.events.LoadEvent`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `bytesTotal` property has changed.

### canPauseChange

Event

Event Object Type: `org.osmf.events.PlayEvent`
property PlayEvent.type = `org.osmf.events.PlayEvent.CAN_PAUSE_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `canPause` property has changed.

The PlayEvent.CAN_PAUSE_CHANGE constant defines the value of the type property of the event object for a canPauseChange event.

### complete

Event

Event Object Type: `org.osmf.events.TimeEvent`
property TimeEvent.type = `org.osmf.events.TimeEvent.COMPLETE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the media has completed playback.

The TimeEvent.COMPLETE constant defines the value of the type property of the event object for a complete event.

### displayObjectChange

Event

Event Object Type: `org.osmf.events.DisplayObjectEvent`
property DisplayObjectEvent.type = `org.osmf.events.DisplayObjectEvent.DISPLAY_OBJECT_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `displayObject` property of the media has changed.

The DisplayObjectEvent.DISPLAY_OBJECT_CHANGE constant defines the value of the type property of the event object for a displayObjectChange event.

### drmStateChange

Event

Event Object Type: `org.osmf.events.DRMEvent`
property DRMEvent.type = `org.osmf.events.DRMEvent.DRM_STATE_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10.1, AIR 1.5

Dispatched when the state of the DRMTrait has changed.

The DRMEvent.DRM_STATE_CHANGE constant defines the value of the type property of the event object for a change to the drmState of a DRMTrait.

### durationChange

Event

Event Object Type: `org.osmf.events.TimeEvent`
property TimeEvent.type = `org.osmf.events.TimeEvent.DURATION_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `duration` property of the media has changed.

The TimeEvent.DURATION_CHANGE constant defines the value of the type property of the event object for a durationChange event.

### isRecordingChange

Event

Event Object Type: `org.osmf.events.DVREvent`
property DVREvent.type = `org.osmf.events.DVREvent.IS_RECORDING_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10.1, AIR 1.5

Dispatched when the `isRecording` property has changed.

The DVREvent.IS_RECORDING_CHANGE constant defines the value of the type property of the event object for an isRecordingChange event.

### loadStateChange

Event

Event Object Type: `org.osmf.events.LoadEvent`
property LoadEvent.type = `org.osmf.events.LoadEvent.LOAD_STATE_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the state of the LoadTrait has changed.

The LoadEvent.LOAD_STATE_CHANGE constant defines the value of the type property of the event object for a loadStateChange event.

### mediaSizeChange

Event

Event Object Type: `org.osmf.events.DisplayObjectEvent`
property DisplayObjectEvent.type = `org.osmf.events.DisplayObjectEvent.MEDIA_SIZE_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `mediaWidth` and/or `mediaHeight` property of the media has changed.

The DisplayObjectEvent.MEDIA_SIZE_CHANGE constant defines the value of the type property of the event object for a mediaSizeChange event.

### mutedChange

Event

Event Object Type: `org.osmf.events.AudioEvent`
property AudioEvent.type = `org.osmf.events.AudioEvent.MUTED_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `muted` property of the media has changed.

The AudioEvent.MUTED_CHANGE constant defines the value of the type property of the event object for a mutedChange event.

### numAlternativeAudioStreamsChange

Event

Event Object Type: `org.osmf.events.AlternativeAudioEvent`
property AlternativeAudioEvent.type = `org.osmf.events.AlternativeAudioEvent.NUM_ALTERNATIVE_AUDIO_STREAMS_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.6

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the number of alternative audio streams has changed.

Dispatched when the number of available alternative audio streams has changed..

### numDynamicStreamsChange

Event

Event Object Type: `org.osmf.events.DynamicStreamEvent`
property DynamicStreamEvent.type = `org.osmf.events.DynamicStreamEvent.NUM_DYNAMIC_STREAMS_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the number of dynamic streams has changed.

The DynamicStreamEvent.NUM_DYNAMIC_STREAMS_CHANGE constant defines the value of the type property of the event object for a numDynamicStreamsChange event.

### panChange

Event

Event Object Type: `org.osmf.events.AudioEvent`
property AudioEvent.type = `org.osmf.events.AudioEvent.PAN_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `pan` property of the media has changed.

The AudioEvent.PAN_CHANGE constant defines the value of the type property of the event object for a panChange event.

### playStateChange

Event

Event Object Type: `org.osmf.events.PlayEvent`
property PlayEvent.type = `org.osmf.events.PlayEvent.PLAY_STATE_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `playing` or `paused` property of the media has changed.

The PlayEvent.PLAY_STATE_CHANGE constant defines the value of the type property of the event object for a playStateChange event.

### seekingChange

Event

Event Object Type: `org.osmf.events.SeekEvent`
property SeekEvent.type = `org.osmf.events.SeekEvent.SEEKING_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `seeking` property of the media has changed.

The SeekEvent.SEEKING_CHANGE constant defines the value of the type property of the event object for a seekingChange event.

### switchingChange

Event

Event Object Type: `org.osmf.events.DynamicStreamEvent`
property DynamicStreamEvent.type = `org.osmf.events.DynamicStreamEvent.SWITCHING_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when a dynamic stream switch change occurs.

The DynamicStreamEvent.SWITCHING_CHANGE constant defines the value of the type property of the event object for a switchingChange event.

### volumeChange

Event

Event Object Type: `org.osmf.events.AudioEvent`
property AudioEvent.type = `org.osmf.events.AudioEvent.VOLUME_CHANGE`

Language Version: | ActionScript 3.0

Product Version: | OSMF 1.0

Runtime Versions: | Flash Player 10, AIR 1.5

Dispatched when the `volume` property of the media has changed.

The AudioEvent.VOLUME_CHANGE constant defines the value of the type property of the event object for a volumeChange event.
Examples How to use this example
TraitEventDispatcherExample.as
Copy

    package
    {
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;

        import org.osmf.elements.VideoElement;
        import org.osmf.events.AudioEvent;
        import org.osmf.events.PlayEvent;
        import org.osmf.media.MediaPlayerSprite;
        import org.osmf.media.URLResource;
        import org.osmf.traits.TraitEventDispatcher;

        public class TraitEventDispatcherExample extends Sprite
        {
            public function TraitEventDispatcherExample()
            {
                super();

                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;

                var mediaPlayerSprite:MediaPlayerSprite = new MediaPlayerSprite();
                var urlResource:URLResource = new URLResource("rtmp://cp67126.edgefcs.net/ondemand/mediapm/strobe/content/test/SpaceAloneHD_sounas_640_500_short");
                var videoElement:VideoElement = new VideoElement();
                videoElement.resource = urlResource;

                var dispatcher:TraitEventDispatcher = new TraitEventDispatcher();
                dispatcher.media = videoElement;

                dispatcher.addEventListener(AudioEvent.VOLUME_CHANGE, onVolumeChange);
                dispatcher.addEventListener(PlayEvent.PLAY_STATE_CHANGE, onPlayStateChange);

                addChild(mediaPlayerSprite);
                mediaPlayerSprite.media = videoElement;
            }

            private function onVolumeChange(event:AudioEvent):void
            {
                trace("onVolumeChange");
            }

            private function onPlayStateChange(event:PlayEvent):void
            {
                trace("onPlayStateChange");
            }
        }
    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00