|
-
anyone else hear that?
bulkLoader - reference loaded clip and load more??
I'm using bulkLoader to load my mp3 and flv files (thanks to dawsonk for hooking me up with the answer there), and now I need to be able to play/pause and jump ahead and back in the movie that I loaded, but I can't figure out how to reference it??
Also, when I go to load another movie/audio from a button click, do I need to do anything with the old instance, or will flash take care of that??
Here's the class:
Code:
package{
import br.com.stimuli.loading.BulkLoader;
import br.com.stimuli.loading.BulkProgressEvent;
import flash.events.*;
import flash.display.*;
import flash.media.*;
import flash.net.*;
public class SimpleExampleMain extends MovieClip{
public var loader : BulkLoader;
public var v : Video;
public var counter : int = 0;
public var mp3:String;
public var flv:String;
public function SimpleExampleMain(mp3,flv) {
loader = new BulkLoader("main-site");
loader.logLevel = BulkLoader.LOG_VERBOSE;
loader.add(flv, {maxTries:6, id:"the-video", pausedAtStart:true});
loader.add(mp3, {"id":"soundtrack", maxTries:1, priority:100});
loader.addEventListener(BulkLoader.COMPLETE, onAllItemsLoaded);
loader.addEventListener(BulkLoader.PROGRESS, onAllItemsProgress);
loader.start();
}
public function onAllItemsLoaded(evt : Event) : void{
var video : Video = new Video();
var theNetStream : NetStream = loader.getNetStream("the-video");
trace("theNetStream "+theNetStream);
addChild(video);
video.attachNetStream(theNetStream);
theNetStream.resume();
video.y = 300;
var soundtrack : Sound = loader.getSound("soundtrack");
soundtrack.play();
}
public function onAllItemsProgress(evt : BulkProgressEvent) : void{
trace(evt.loadingStatus());
}
}
}
and here's how I'm loading it:
Code:
var mp3:String="audioFile.mp3";
var flv:String="videoFile.flv";
var se:SimpleExampleMain=new SimpleExampleMain(mp3,flv);
addChild(se);
and here are my button functions:
Code:
public function audioStop(e:Event):void {
//this is how I was doing it when I used flvComponent
//video_mc.stop();
//this is what I tried, but it gives errors because theNetStream is declared in a different class/function...I think...
//theNetStream.stop();
//this is what I was using for the sound previously
//pausePoint=channel.position;
//channel.stop();
isPlaying=false;
}
public function nextScreen(e:Event):void {
mp3="newfile.mp3";
flv="newfile.flv";
//just needs to call bulkLoader again but I'm not sure if I need to delete the old items, can I just do:
var se:SimpleExampleMain=new SimpleExampleMain(mp3,flv);
addChild(se);
}
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
-
Total Universe Mod
You have SimpleExampleMain set up as media loader and controller. In terms of good OOP, its just a little incomplete. Other classes ie. your main timeline should not have direct control over the Sound or NetStream objects. Instead, SimpleExampleMain should have an interface in the form of public methods such as pauseSound() or seekFLVto() which parents of SimpleExampleMain instances can call.
For example you might use something like this in SimpleExampleMain:
public function seekFLVto(seconds:Number):void{
theNetStream.seek(seconds);
}
Then later call
se.seekFLVto(30); //or whatever
That encapsulates the Sound and NetStream/Video objects.
Finally, as3 does not presume any type of clean up and the major offenders are timelines that are playing, files that are loading or streaming and media objects such as NetStream or SoundChannel.
As one of your interface methods, you should create a destroy() function that stop, closes and nullifies any objects the class created.
Something to the effect of:
PHP Code:
public function destroy():void{ try{ mySoundChannel.stop(); } catch{}; try{ myNetStream.close(); } catch{}; finally{ mySoundChannel = null; mySound = null; myNetStream = null; } }
So that you can call se.destroy(); before you create a new SimpleExampleMain instance.
And that's my 2000'th post ya'll! I'm out!
-
anyone else hear that?
Wow...2000th!! I feel honored...
Thanks for the input and guidance...just getting into OOP and AS3 and figuring out what goes in what classes, how to split things up, etc. A bit daunting at first, but, if I don't start, I'll just stay behind. 
Thanks and I'll let you know how it works!
Love like you've never been hurt, live like there's no tomorrow and dance like nobody's watching.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|