Jump to content
GreenSock

failure13

VideoLoader URL trouble

Recommended Posts

Previously, when i wanted to get flashvars from .html page (using default flash loader), i was making it this way:

VIDpath:Object = LoaderInfo(this.root.loaderInfo).parameters.GetVideoURL;

But when i pass such thing to VideoLoader i got error

Scene 1, Layer 'actions', Frame 1, Line 42 1047: Parameter initializer unknown or is not a compile-time constant.

 

How would i need to call for an URL from html now?

 

P.S. And also i'm not sure how to monitor video download progress, like on youtube for example, if i got rectangle named downloadProgress, what should i do with videoLoader?

Link to comment
Share on other sites

Hi,

 

I don't think that is a VideoLoader error.

Please remove your VideoLoader code and try to trace or display the value of VIDpath in a textfield.

 

Do you still get the error without VideoLoader?

 

I assume you want to pass VIDPath into the VideoLoader constructor as the url, but keep in mind that VideoLoader's url should be a String or URLRequest.

 

---

 

To make a progress bar, assign an onProgress callback to your VideoLoader that sets the scaleX of downloadProgress equal to the VideoLoader's progress

 

import com.greensock.loading.*;
import com.greensock.events.*;
var myVideo:VideoLoader = new VideoLoader("video.flv", {onProgress:progressHandler});

function onProgress(e:LoaderEvent):void{
downloadProgress.scaleX = myVideo.progress;
}

 

Great VideoLoader tutorial http://active.tutsplus.com/tutorials/actionscript/smart-as3-video-loading-with-greensock-loadermax-free-active-premium/

 

Loading videos is virtually the same as loading images. Here is a tutorial of some of the basic concepts. It uses ImageLoader, but the events and properties are useful for VideoLoader too.

 

http://www.snorkl.tv/2011/08/loading-images-with-loadermax-load-and-track-the-progress-of-multiple-images/

Link to comment
Share on other sites

Yep, doesn't work also...But hell, i still don't understand something about flash syntax probably...

Please take a look, maybe you'll understand what's wrong:

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;
import com.greensock.loading.display.*;

stage.align = "TL";
stage.scaleMode = "noScale";

// create new gallery instance
var video1:VideoLoader = addVideo(
"Videos/REHA720x576.mp4",
);

/////////////////////////////////////////// VIDEO PLAYER //////////////////////////////////////////

function addVideo(VIDpath:Object = LoaderInfo(this.root.loaderInfo).parameters.GetVideoURL):VideoLoader {

// url of video file
var VIDpath:String;
// create video loader
var video:VideoLoader = new VideoLoader(VIDpath, {
name: "video",
autoPlay: false,
container: this,
alpha: 0,
bgColor: backgroundsColor,
scaleMode: "proportionalInside",
centerRegistration: true,
onComplete: initVideo,
onError: errorCatch
});

}

What i want, is that function addVideo had it's default path value from html flashvar, like this VIDpath:Object = LoaderInfo(this.root.loaderInfo).parameters.GetVideoURL (i used to have it in past, and it was type of Object, working..), but also i would like to pass parameters of new URL, for this function (if needed), like this:

var video1:VideoLoader = addVideo(
"Videos/REHA720x576.mp4",
);

And this is String type...

So i don't know what to do, VideoLoader use only String or URLRequest, as you said, but i need to pass either String or Object (i believe)...

Maybe there are some other way to retrieve URL from html's FlashVars and write it as String or URLRequest?

 

Probably you missunderstood me about progress...I already got progress bar associated with time and mouse scrubber, what i need is download bar to monitor how much of video have been downloaded already...What you have showed seem to be same that i've done to monitor progress of video playback.

 

I was watching those tutorials very precies already, but i feel that there are something i do wrong still in some scenarios...sorry for that :)

Link to comment
Share on other sites

I believe that LoaderInfo(this.root.loaderInfo).parameters is an Object. The property value you get from that object is most likely a string like the following

 

LoaderInfo(this.root.loaderInfo).parameters.someProperty

 

You may want to try to hunt down that new error you are getting. Not uncommon for Adobe to introduce new issues with new versions of the Flash player. Maybe search for loaderInfo and see if your implementation is correct or if there is a bug on their end.

 

I don't know what to tell you but someVideoLoader.progress does represent the download progress NOT the playback progress.

 

someVideoLoader.playProgress would track the amount of video that has played

http://www.greensock...ml#playProgress

 

If you continue to see a discrepancy, please upload a very basic example that loads a single video.

Link to comment
Share on other sites

Well, i managed to get progress work, but it's like...Even when i test it in flash with modem speed it's immidiately show whole progress as loaded (that's why i thought it's not working)...How could it load that fast, that it's even impossible to notice difference between scaleX = 0 and scaleX = 1? Probably i still do something wrong or missing something?

 

The property value you get from that object is most likely a string like the following

 

LoaderInfo(this.root.loaderInfo).parameters.someProperty

 

 

Well yeah, in my case it actually is a string, just a video URL...

But it still act as an object for the var, and VideoLoader can't read it and thtow IO error back...

 

How would you normally retrieve URL from html page using GS VideoLoader?

Link to comment
Share on other sites

I don't understand the trouble you are having with loaderInfo.parameters.

 

I made a very simple example. Nothing fancy

 

as3 code:

 

import com.greensock.*;
import com.greensock.loading.*;

var loaderParams:Object = stage.loaderInfo.parameters;
var videoURL:String = loaderParams.video;

var_txt.text = videoURL;

var myVideo:VideoLoader = new VideoLoader(videoURL, {container:this});
myVideo.load();

 

standard embed code (note FlashVars param):

 

<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="loaderInfo" align="middle">
<param name="movie" value="loaderInfo.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="video=angrybirds.flv" />


<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="loaderInfo.swf" width="550" height="400">
<param name="movie" value="loaderInfo.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
				<param name="FlashVars" value="video=angrybirds.flv" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>

I zipped up the whole working example with CS5 fla, swf, greensock code, html and video

 

When you compile you will get a run-time error about the video param not existing because it isn't in the html page (you can add a conditional to get around that). When you view the swf in the loaderInfo.html page it works fine.

 

-=-

 

As for the progress happening very fast, Flash's "simulate download" feature isn't always the best. I've had problem's with it in the past. Best thing is to test on a real server.

loaderInfo.zip

Link to comment
Share on other sites

Wow, Carl, thank you a lot!

I missunderstood one thing at first, that those can be divided on Object and String, that totally makes sense now:

 

var loaderParams:Object = stage.loaderInfo.parameters;

 

var videoURL:String = loaderParams.video;

So when i put videoURL directly in VideoLoader, now it works perfectly, but...

 

http://www.sendspace.com/file/xpe1ga

 

Take a look here, what i have problem with...

If you will do it like this:

function addVideo(VIDpath:String = videoURL):VideoLoader {
....
}

 

This will immideately give you an error:

Scene 1, Layer 'Layer 1', Frame 1, Line 24 1047: Parameter initializer unknown or is not a compile-time constant.

But i totally don't understand why, and got no one to ask except you (i know that this is not directly GS question, but still...)

 

What i want is videoURL to be the default path for addVideo function, if there are no other String specified...

Take a look at simple example, i'm sure you can understand what i'm doing wrong, it seem like some kind of flash bug (or my as syntax dyslexia)...

 

About progress - everything is fine now, you was right...I just wonder that simulate download doesn't react as with flash native written player i used before :) But anyway on server it shows progress perfectly reasonable!

thx a lot!

 

Oh yeah, and i am trying to understand how to make "click on progress line to move on the specific place in video where it was clicked", http://active.tutsplus.com/tutorials/actionscript/smart-as3-video-loading-with-greensock-loadermax-free-active-premium/ like here you can click anywhere you want and go there, but there are nothing i can see in the tutorial about how to make it...

 

P.S. I meant not scrubbing with scrubber, exactly click-to-go-to-mouse is what i need :)

Link to comment
Share on other sites

function addVideo(VIDpath:String = videoURL):VideoLoader

 

VIDpath is the Parameter

videoURL is the 'Parameter initializer' i.e. the default value

 

When setting a default for a parameter, you are only allowed to use compile time constants. These will usually be literal values (e.g. 9 {Int}, "word" {String}, true {Boolean} etc). You can't use a dynamic variable for this unfortunately.

 

What you can do instead, is use null as your default value, and if the parameter is null set it to your default e.g.

function addVideo(VIDpath:String = null):VideoLoader {
 if (VIDpath === null) {
   // assuming videoURL is initialised at this point (in a constructor?)
VIDpath = videoURL;
 }
}

  • Like 2
Link to comment
Share on other sites

For the "click-to-go-to-mouse" functionality you asked about below is some code that allows you to click anywhere on a MovieClip and based on the mouseX in relation to the width of that clip you can generate a number between 0 and 1 which can be used as the VideoLoader's progress

 

 

Just paste this into a blank AS3 fla and compile.

Click the red bar that appears.

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.TextField;

//create a progressBar
var progressBarContainer:MovieClip = new MovieClip;
var progressBackground:Shape = createRectangle(200, 10, 0x000000);
var progressIndicator:Shape = createRectangle(200, 10, 0xff0000);

progressBarContainer.x = 50;
progressBarContainer.y = 100;

progressBarContainer.addChild(progressBackground);
progressBarContainer.addChild(progressIndicator);
addChild(progressBarContainer);

var output:TextField = new TextField();
output.x = progressBarContainer.x;
output.y = progressBarContainer.y + 15;
addChild(output);


progressBarContainer.addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(e:MouseEvent):void{
//convert mouseX to a number between 0 and 1
var newProgress:Number =  progressBarContainer.mouseX / progressBarContainer.width ;
progressIndicator.scaleX = newProgress;
output.text = String(newProgress);
trace("newProgress = " + newProgress);
}



function createRectangle(w:Number, h:Number, color:uint=0xFF0000):Shape {
var s:Shape = new Shape();
s.graphics.beginFill(color, 1);
s.graphics.drawRect(0, 0, w, h);
s.graphics.endFill();
return s;
}

  • Like 1
Link to comment
Share on other sites

jamiejefferson

Hey, thank you!

That makes sense, pity that no dynamic variables allowed...

 

That's a great idea about null, and i also have an idea about just writing in VideoLoader alternateURL: VIDpath

And it works also, pretty clean!

 

carl schooff

Works like charm, thank you again! :)

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.
×