Jump to content

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

MP3Loader return object error

Recommended Posts

So I used the demo code and was trying to load in mp3 sounds and then get the MP3Loader class to have access to the volume, etc. The problem was that it gave an error stating that it can't convert the object to that type. If I change the 'snd1' variable in the completeHandler to be of type 'Sound' then it works fine (well..after I put snd1.play() on the next line). Am I not doing this correctly?


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

//append several loaders
queue.append( new MP3Loader("mp3/audio.mp3", {name:"audio", repeat:2, autoPlay:true}) );

//start loading

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

function completeHandler(event:LoaderEvent):void {
   var snd1:MP3Loader = LoaderMax.getContent("audio");
   trace(event.target + " is complete!");

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

Link to comment
Share on other sites

The "content" of an MP3Loader is a Sound object. I think you meant to do getLoader() instead of getContent(), like:


var snd1:MP3Loader = LoaderMax.getLoader("audio");


You can control the audio directly through the loader.

Link to comment
Share on other sites

On other question. I'm now working with swf files. I've added:


queue.append( new MP3Loader("swf/ani1.swf", {name:"swfAni1", container:this, autoPlay:true}) );


So in the complete event function how would I get the SWFLoader object back? I've tried a number of combinations but I either get errors or no errors but nothing displays. I thought it would addChild automatically? (when I addChild it fails). Here is how I thought it would work:


var ani_1:SWFLoader = LoaderMax.getLoader("swfAni1");
// Then I could use ani_1 with all it's properties...should already be added to the screen..etc.


Apparently I'm wrong in my assumption. What am I missing?

Link to comment
Share on other sites

I see two problems right away:


1) You're using an MP3Loader to load an swf. You need a SWFLoader :)



queue.append( new MP3Loader("swf/ani1.swf", {name:"swfAni1", container:this, autoPlay:true}) );


queue.append( new SWFLoader("swf/ani1.swf", {name:"swfAni1", container:this, autoPlay:true}) );


2) You're trying to use the SWFLoader instead of its content. Remember, a SWFLoader will create a ContentDisplay Sprite into which it will load your content. So you can put that ContenDisplay wherever you want. Scale it, rotate it, add MouseEvent listeners, etc. Like this:


var ani_1:ContentDisplay= LoaderMax.getContent("swfAni1");
TweenLite.to(ani_1, 1, {x:100, scaleX:2});


If you haven't read it already, this might be helpful: http://www.greensock.com/loadermax-tips/

Link to comment
Share on other sites

Oh my crap. Thanks. Just one of those days where you stare at your code and just can't see it. Thank you so much. I've been waiting for someone to create a loader class like this. Thank you, thank you, thank you!

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.