Hi Jack,
Really sorry for the inconvenience caused and thanks for the response. The application is working fine. Suppose if i have 6 items in my xml and loading one by one as you explained above, the memory keeps on increasing untill the 6th item is loaded and then it's somewhat stable at the same level.What i am thinking is for example if the first item takes 20000 k in memory, then on loading the second one that 20000 k of first item should be released and then the second one should be loaded. I have pasted my full coding below, am i still doing something wrong here?
here is my coding
package com { import flash.utils.Timer; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; import flash.display.Sprite; import flash.events.TimerEvent; import flash.display.MovieClip; import com.greensock.*; import com.greensock.loading.*; import com.greensock.layout.ScaleMode; import com.greensock.loading.display.*; import com.greensock.events.LoaderEvent; import com.greensock.loading.core.LoaderItem; public dynamic class Screensaver extends Sprite{ private var xmlArray:Array; private var mediaHolder:Sprite; private var mediaContent:String; private var videoDuration:Number; private var increment:Number = 0; private var timer:Timer = new Timer(1000);
private var currVideo:VideoLoader; private var currentMedia:LoaderItem; private var imgHolder:ImgHolder = new ImgHolder(); private var loader:LoaderMax = new LoaderMax({name:"mediaLoader", onComplete:completeHandler}); LoaderMax.activate([VideoLoader, ImageLoader, SWFLoader]); // constructor function public function Screensaver() { addChild(imgHolder); imgHolder.alpha = 0; mediaHolder = new Sprite(); imgHolder.addChild(mediaHolder); imgHolder.width = stage.stageWidth; imgHolder.height = stage.stageHeight; imgHolder.scaleX < imgHolder.scaleY ? imgHolder.scaleY = imgHolder.scaleX : imgHolder.scaleX = imgHolder.scaleY; dataSource(); } private function dataSource():void{ var xmlLoader:URLLoader = new URLLoader(); xmlLoader.load(new URLRequest("DB/screensaver.xml")); xmlLoader.addEventListener(Event.COMPLETE, xmlHandler, false, 0, true); } // function to parse xml and validate based on from and to date private function xmlHandler(e:Event){ var xml:XML = new XML(e.target.data); var currDate:Date = new Date(); xmlArray = new Array(); for(var count:uint=0;count<xml.item.length();count++){ var startDate:String = xml.item[count].attribute("from"); var endDate:String = xml.item[count].attribute("to"); if(currDate>=new Date(startDate) && currDate<=new Date(endDate)) xmlArray.push({type:xml.item[count].attribute("media"), source:xml.item[count].attribute("src"), delay:xml.item[count].attribute("duration")}); } appendLoaders(); } // function to append the filtered media into the LoaderMax object private function appendLoaders():void{ for(var count:uint=0;count<xmlArray.length;count++){ var str:String = xmlArray[count].type switch(str){ case "image": loader.append(new ImageLoader(xmlArray[count].source, {name:"media"+count, scaleMode:"proportionalInside", width:imgHolder.width, height:imgHolder.height, vAlign:"center"})); break; case "video": loader.append(new VideoLoader(xmlArray[count].source, {name:"media"+count, scaleMode:"proportionalInside", autoPlay:false, width:imgHolder.width, height:imgHolder.height})); break; case "swf": loader.append(new SWFLoader(xmlArray[count].source, {name:"media"+count, scaleMode:"proportionalInside", autoPlay:true, width:imgHolder.width, height:imgHolder.height, vAlign:"center"})); break; } } loader.load(); } // function to load image/video/swf private function loadMedia():void{ clearContainer(); if (currentMedia != null) currentMedia.unload(); if(currVideo!=null) currVideo.unload(); currentMedia = loader.getChildAt(increment); mediaContent = xmlArray[increment].type; currentMedia.load(); if (mediaContent == "video") { currVideo = loader.getChildAt(increment); currVideo.playVideo(); currVideo.addEventListener(VideoLoader.VIDEO_COMPLETE, videoCompleted, false, 0, true); }else{ startTimer(); } imgHolder.alpha = 1; mediaHolder.scaleX = 1/imgHolder.scaleX; mediaHolder.scaleY = 1/imgHolder.scaleY; imgHolder.x = (stage.stageWidth/2) - (imgHolder.width/2); imgHolder.y = (stage.stageHeight/2) - (imgHolder.height/2); mediaHolder.addChild(currentMedia.content); TweenLite.from(imgHolder, 1, {alpha:0, x:stage.stageWidth+mediaHolder.width}); (increment==xmlArray.length-1)?increment=0:increment++; } // function called at the end of video completion private function videoCompleted(e:Event):void{ currVideo.pauseVideo(); currVideo.gotoVideoTime(0); loadMedia(); } // function triggered when the LoaderMax completes loading function completeHandler(event:LoaderEvent):void { loader.unload(); loadMedia(); } // function to start the timer private function startTimer():void{ timer.delay = (mediaContent != "video")?Number(xmlArray[increment].delay)*1000:videoDuration*1000; timer.start(); timer.addEventListener(TimerEvent.TIMER, timerControl); } //function to be called when the timer reaches the specified duration private function timerControl(e:TimerEvent):void{ timer.stop(); TweenLite.to(imgHolder, 1, {alpha:0, x:-mediaHolder.width, onComplete:loadMedia}); }
// function to clear the container before loading any content private function clearContainer():void{ while(mediaHolder.numChildren>0){ mediaHolder.removeChildAt(0); } } } }