Jump to content
GreenSock

HyperNerd

Setting VideoLoader Depth

Recommended Posts

Hello all,

 

I'm brand new to LoaderMax/VideoLoader and I am looking into using it for cue point benefits over NetStream with the Gaia Framework. I have succesfully loaded my video, which needs to run in the background with buttons on top. My question is, how do I set the VideoLoader to the bottom of the depth stack? My recent attempt kicks back an "Implicit coercion" error:

 

import com.greensock.TweenMax;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import com.greensock.*;
import com.greensock.events.LoaderEvent;
import com.greensock.layout.*;
...
function initVideo():void
 {
//create a VideoLoader
var video:VideoLoader = new VideoLoader("Liberation.f4v", {name:"myVideo", container:this, width:1280, height:720, scaleMode:"proportionalInside", bgColor:0x000000, autoPlay:true, volume:0, requireWithRoot:this.root, estimatedBytes:75000});
setChildIndex(video, 0);
//start loading
video.load();
//tween the volume up to 1 over the course of 2 seconds.
TweenLite.to(video, 2, {volume:1});
 }

 

setChildIndex seems to be the culprit.. How to add at a given depth?

 

Thanks!

Link to comment
Share on other sites

Remember, a VideoLoader isn't a DisplayObject. It creates a ContentDisplay that is a DisplayObject (a Sprite actually), and that's where it puts the video. The VideoLoader's "content" refers to that ContentDisplay. So your code would look like:

 

setChildIndex(video.content, 0);

Link to comment
Share on other sites

Thank you for clearing that up!

 

Next question - I have an onPause function that decreases the volume over 1 second and then sends an onComplete to pause the video. However, I'm receiving error:

 

Error #1069: Property pauseVideo not found on flash.media.Video and there is no default value.

at pages::ProductAPage/soundFadeComplete()

at Function/http://adobe.com/AS3/2006/builtin::apply()

at com.greensock.core::TweenCore/complete()

at com.greensock::TweenLite/renderTime()

at com.greensock.core::SimpleTimeline/renderTime()

at com.greensock::TweenLite$/updateAll()

 

function initVideo():void
 {
//create a VideoLoader
video = new VideoLoader("Liberation.f4v", { name:"myVideo", container:this, width:stage.stageWidth, height:stage.stageHeight, scaleMode:"proportionalInside", autoPlay:true} );
video.load();
setChildIndex(video.content, 0);
 }

 function onPause(e:MouseEvent):void{
  pauseBTN.visible = false;
  playBTN.visible = true;
  testBTN.visible = true;

//tween volume to 0 over the course of 1 seconds
TweenLite.to(video, 1, {volume:0, onComplete: soundFadeComplete});
 }

function soundFadeComplete():void
	 {
video.pauseVideo();
 }



function onPlay(e:MouseEvent):void
{
pauseBTN.visible = true;
playBTN.visible = false;
testBTN.visible = false;

video.playVideo();
TweenLite.to(video, 1, {volume:1});
 }

 

Any idea what is wrong with my video.pauseVideo(); / playVideo(); approach?

Link to comment
Share on other sites

Interestingly, if I place video.pauseVideo(); within the onPause function it does work, but then I still get the following error for the video.playVideo(); within the onPlay command:

#1069: Property playVideo not found on flash.media.Video and there is no default value.

at pages::ProductAPage/onPlay()

 

That also would negate the purpose of decreasing the video volume before pausing... Sorry if this is newb stuff, but I'm trying to understand.

Link to comment
Share on other sites

Based on the error and your code, it sounds like you must have declared your "video" variable with a type of "Video" (as in flash.media.Video) instead of "VideoLoader" (as in com.greensock.loading.VideoLoader). Is that correct? That would certainly explain all the errors. Correcting the variable's type should resolve the errors.

Link to comment
Share on other sites

Ahhhh! That was it! I was actually attempting to use both VideoLoader and flash.media.Video in the same project. Looks like it was defaulting to flash.media.Video. I should probably get over it and just use the awesome VideoLoader exclusively, huh? :-P

Thank you SO much for guiding me in the right direction!

Link to comment
Share on other sites

No problem! Glad you got things squared away.

 

Enjoy!

  • Like 1
Link to comment
Share on other sites

I should start a new topic, but my next task is to understand how to launch an embedded cue point event when the video is paused. If you would kindly point me in the right direction or show me what the basis of that code would look like? Also, I know flash.media.Video can't read cue points within F4V, only FLV. Is this the case with VideoLoader as well?

 

**UPDATED TO NEW POST**

Link to comment
Share on other sites

Hi,

 

I don't understand the part about launching a cue point when the video is paused. Feel free to elaborate. Are you referring to scrubbing the video?

 

Below is some general code for reading the embedded cuePoint data out of an flv that was loaded using a VideoLoader. Furthermore it is set up to trace information about the cue point is reached.

 

load flv:

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import flash.events.VideoEvent;

var cuePoints:Array = [];
var vid:VideoLoader = new VideoLoader("cuepoints.flv",{container:this,onInit:getAllCuePoints});
vid.addEventListener(VideoLoader.VIDEO_CUE_POINT, onCue);



function onCue(e:LoaderEvent):void
{
trace("cuepoint fired: " + e.data.name);
}

function getAllCuePoints(e:LoaderEvent)
{

trace(" *** Embedded CuePoint Data *** ");

//grab the array of cuePoint objects from the VideoLoader's metadata

cuePoints = vid.metaData.cuePoints;
trace("\n# of cuePoints = " + cuePoints.length);
for (var i:int = 0; i < cuePoints.length; i++)
{
trace(cuePoints[i].name + " : " + cuePoints[i].time);
}
trace("\n ***  *** \n");
}

vid.load();

 

Also, you can certainly use VideoLoader to load f4v files with cue points but there are some known oddities regarding when the cue point data will be available. Please read: http://forums.greens...9779#entry19779

 

The code below shows how to account for the f4v onInit issue discussed in the link above

 

Get cuePoint data from F4V

 

 

function getAllCuePoints(e:LoaderEvent) {

trace(" *** Embedded CuePoint Data *** ");

//*** FOR F4V: check to see if the cuePoint data exists

if (vid.metaData.cuePoints) {

//grab the array of cuePoint objects from the VideoLoader's metadata

cuePoints = vid.metaData.cuePoints;
trace("\n# of cuePoints = " + cuePoints.length);
for (var i:int = 0; i < cuePoints.length; i++) {
trace(cuePoints[i].name + " : " + cuePoints[i].time);
}
trace("\n ***  *** \n");
}
}

 

Attached is a working sample of the flv version including flv and CS5 fla. GreenSock files not included.

cuepoints.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×