Jump to content

Search In
  • More options...
Find results that contain...
Find results in...

Basic questions on loading FLV and MP4

Recommended Posts

I have some code that works great for external SWF files, but I'm struggling to find good samples and what I have to tweak to load FLV or MP4 files...

Basically my problem is in completeHandler where I simply want to play the video - I can't get it to go, and get this error - and I've tried .playVideo(); and no go either... I know I'm missing something basic - so basic it isn't even IN the samples I've been reviewing...


Although I poke around in as3, I am not good enough to dig into the API documentation and make heads or tails out of it - and I just can't find *complete* samples of how to do this that don't make assumptions which I guess I don't have setup right.


TypeError: Error #1034: Type Coercion failed: cannot convert flash.media::Video@2be513f9 to flash.display.MovieClip.


var Comic_mc:MovieClip;

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

function PreviewLoad(ComicSWF:String) {

// for testing, hardcode
//ComicSWF = "SWFTest.swf";
//ComicSWF = "MP4Test.mp4";
ComicSWF = "FLVTest.flv";

var queue:LoaderMax = new LoaderMax({name:"comicQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

	if (ComicSWF.indexOf(".mp4") > 0) {
	queue.append( new VideoLoader(ComicSWF, {name:"comicClip", container:this, width:640, height:360, z:1000000, autoPlay:false}) );		
	if (ComicSWF.indexOf(".flv") > 0) {
	queue.append( new VideoLoader(ComicSWF, {name:"comicClip", container:this, width:640, height:360, z:1000000, autoPlay:false}) );		
if (ComicSWF.indexOf(".swf") > 0) {
	queue.append( new SWFLoader(ComicSWF, {name:"comicClip", container:this, width:640, height:360, z:1000000, autoPlay:false}) );		


function progressHandler(event:LoaderEvent):void {
   trace("progress: " + event.target.progress);

function completeHandler(event:LoaderEvent):void {
   var ComicDisplay:ContentDisplay = LoaderMax.getContent("comicClip");
   trace(event.target + " is complete!");
Comic_mc = ComicDisplay.rawContent;
Comic_mc.x = 10;
Comic_mc.y = 10;

function errorHandler(event:LoaderEvent):void {
   trace("error occured with " + event.target + ": " + event.text);

Link to comment
Share on other sites

up top in your code you are saying that Comic_mc is a MovieClip, so the error is saying that this MovieClip var can't reference a video.



to get your video to display and play try this


//somewhere at the top of your code:

var Comic_mc:MovieClip = new MovieClip();

//replace your current completeHandler with:

function completeHandler(event:LoaderEvent):void {

//get a reference to your VideoLoader so you can control the video
   var comicVideo:VideoLoader = LoaderMax.getLoader("comicClip");
   trace(event.target + " is complete!");

  Comic_mc.x = 10;
  Comic_mc.y = 10;



//tell the VideoLoader to play






some things to note. when you set up your loader and say container:this, you are specifying what displayObject will hold your loader's content. currently this refers to your main timeline / stage. you could just use container:Comic_mc and save yourself the trouble of adding it in your onCompleteHandler.


also for all those if statements that determine the type of loader you are using, you can look into LoaderMax.parse() which automatically detects the type of asset you are loading and creates the appropriate Loader type: Image, Video, Swf etc.


although your code currently is set up well enough to load a variety of assets, your onCompleteHandler is not really ready to deal with different asset types. as you are seeing now, telling a video to play is different than telling a swf to play. if you are loading multiple asset types, you may need some conditional logic in your completeHandler to deal with the different media types.

Link to comment
Share on other sites

Thank you Carl, I was able to get it to work! I am going to move to loading FLVs instead of SWFs anyway, so I can simplify and go this route - appreciate the excellent help.


 function completeHandlerVID(event:LoaderEvent):void {
   var ComicVideo:VideoLoader = LoaderMax.getLoader("comicVideo");

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.