Jimmery
Jimmery

Reputation: 10139

YouTube ActionScript 3.0 API getting the state from onStateChange

According to the YouTube ActionScript 3.0 Player API, the onStateChange event returns a signed integer from -1 to 5, however I am having problems getting at that integer.

ActionScript 3.0 code:

loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3&modestbranding=true"));

function onLoaderInit(event:Event):void{
    loader.content.addEventListener("onStateChange", onPlayerStateChange);
}

function onPlayerStateChange(event):void{
    trace(event);
}

This trace gives me the following output:

[Event type="onStateChange" bubbles=false cancelable=false eventPhase=2]
[Event type="onStateChange" bubbles=false cancelable=false eventPhase=2]
[Event type="onStateChange" bubbles=false cancelable=false eventPhase=2]

The ActionScript code works fine, its just getting at the state value that I am struggling with.

The only property that kinda looks like what I want is the eventPhase property, but I know its not this as its the same value every time (the API states that the first state returned will be -1) and its also an unsigned integer.

Can anyone tell me how to get at the value I need?

Upvotes: 1

Views: 127

Answers (1)

net.uk.sweet
net.uk.sweet

Reputation: 12431

From memory, I think you probably want the data property of the event object:

function onPlayerStateChange(event):void{
    trace(event.data);
}

If not, and for future reference, stick a breakpoint in the body of your listener and then you can inspect the properties of the event object directly. Trace will only display a string representation which isn't always useful for complex objects.

Upvotes: 2

Related Questions