I have a as3 application that has multiple frames with embed flvs. Based on the value from an xml file, a specific frame is selected and the movie is played. When the choose another link the flv is stoped and another is played automatically. This is not elegant but it worked fine until i realised that the sound for any video will go when memory hit about 160 mb in the projector file. What i want to know is:
ie (I figure if the memory cannot be cleaned up after an embed file has finished playing then i will have to load swf file and unload . i have loaded files already, but unloading is the problem)
so I decided to go with loading/unloading external swf files. Here is my code but i can get unloadAndStop or removeChild to work.
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//part from xml processor function
theImagePath = "flash/"+myXML..item_video_link[n];
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);
myImageLoader.load(myImageRequest);
}
function showMeTheVideo(evt:Event):void{
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);
}
stopVideo(sectionname):viod{
if(detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.numChi ldren !=0){
trace("what is the number of children: "+numChildren);
myImageLoader.unloadAndStop();
detailsMovieClip_mc.details_video_holder.
dynamicVideoHolder.removeChild(myImageLoader);
}
}
try:
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//part from xml processor function
theImagePath = "flash/"+myXML..item_video_link[n];
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
if(myImageLoader){
if(myImageLoader.content){
myImageLoader.unloadAndStop();
}
}
if(detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.numChi ldren !=0){
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);
}
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);
myImageLoader.load(myImageRequest);
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);
}
function showMeTheVideo(evt:Event):void{
// not sure what you want to do here, if anything.
}
use:
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//part from xml processor function
theImagePath = "flash/"+myXML..item_video_link[n];
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
if(myImageLoader){
if(myImageLoader.content){
myImageLoader.unloadAndStop();
}
}
if(myImageLoader.stage){
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);
}
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);
myImageLoader.load(myImageRequest);
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);
}
function showMeTheVideo(evt:Event):void{
// not sure what you want to do here, if anything.
}
use:
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//part from xml processor function
theImagePath = "flash/"+myXML..item_video_link[n];
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
if(myImageLoader){
if(myImageLoader.content){
myImageLoader.unloadAndStop();
}
if(myImageLoader.stage){
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);
}
}
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);
myImageLoader.load(myImageRequest);
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);
}
function showMeTheVideo(evt:Event):void{
// not sure what you want to do here, if anything.
}
I have tried the code below as i stated above but got the error message:
"Error #1009: Cannot access a property or method of a null object reference."
referring to this line: if(myImageLoader.stage){
Any suggestions? Thank you.
kglad wrote:
use:
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//part from xml processor function
theImagePath = "flash/"+myXML..item_video_link[n];
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
if(myImageLoader){
if(myImageLoader.content){
myImageLoader.unloadAndStop();
}
if(myImageLoader.stage){
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld( myImageLoader);
}
}
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);
myImageLoader.load(myImageRequest);
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);
}
function showMeTheVideo(evt:Event):void{
// not sure what you want to do here, if anything.
}
the number of children is not relevant to the code i suggested.
the code i suggested removes your loaded swf from the display list and stops the swf (if you're publishing for fp 10 or better).
but you're probably reloading the same swf after doing that. ie, when you call loadTheMovie you must change the argument passed in the loadTheMovie function call or you'll see the same swf load.
To make sure the complexities of my project are not inerfaring with the code you gave i created a test and extracted your code in and made it so that every five second a new movie clip is automaticcally loaded. it does load but it does not unload. I do see the trace statement which tells me that the code ran but it does not produce the results i need, which is to unload the old movie. It does do a new load without removing old movie resulting in multpiple instances of the movies playing, here as you can see nothing has changed except how the movies get called.
var swfVideoURL:Array = ["flash/shopping.swf","flash/alltours.swf"];
var numPics:Number=swfVideoURL.length;
var nextPic:Number=0;
var nextImageLoadInterval:uint=0;
var myImageLoader:Loader;
var myImageRequest:URLRequest;
var theImagePath:String;
//initialize theimagepath
theImagePath = "flash/shopping.swf";
loadTheMovie(theImagePath);
function loadTheMovie(theImagePath):void{
if(myImageLoader){
if(myImageLoader.content){
trace("attempting to unload");
myImageLoader.unloadAndStop();
}
if(myImageLoader.stage){
trace("attempting to remove from memory");
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.removeChi ld(myImageLoader);
}
}
myImageLoader = new Loader();
myImageRequest= new URLRequest(theImagePath);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showM eTheVideo);
myImageLoader.load(myImageRequest);
detailsMovieClip_mc.details_video_holder.dynamicVideoHolder.addChild( myImageLoader);
}
function showMeTheVideo(evt:Event):void{
nextImageLoadInterval = setInterval (loadTheMovieStart, 5000);
}
function loadTheMovieStart():void{
nextPic=(nextPic+1)%numPics;
theImagePath = swfVideoURL[nextPic];
trace(theImagePath)
loadTheMovie(theImagePath);
}
Message was edited by: jahflasher
That is exactly waht i did . I created a new doc with your code alone for testing . Is it possible i could send the test fla file? Or you can download the test file here: http://www.database-technologies.com/flv_play_back_test_2.rar
I applied a clear inverval and it worked:
function loadTheMovieStart():void{
clearInterval(nextImageLoadInterval);
nextPic=(nextPic+1)%numPics;
theImagePath = swfVideoURL[nextPic];
trace(theImagePath)
loadTheMovie(theImagePath);
}
However this is the test code. In The real project that does not use a setinterval the code does not work. I will have to dig deeper
most likely the code is working. you're just not seeing what you expect.
for example, the setInterval problem didn't prevent the code i suggested from working correctly. it was working correctly. you just failed to see what you expected. you were expecting loadTheMovie to be called once every 5 seconds while you were actually calling it 2,3,4 etc times after 10,15,20 etc seconds.
I did a test in the real world project and made a discovery. Instead of calling a function to remove the loaded swf file after i click a button, i used the example code with set interval to run after 5 seconds. The swf was removed because i did not see the video player, but the sound was still playing. while in the test everything was removed and stopped. Any ideas?
North America
Europe, Middle East and Africa
Asia Pacific