[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 690
  • Last Modified:

loading and unloading external SWF and display the jpg file

I have a window created by FlexBuilder/Actionscript 3. I am trying to play a SWF movie clip and after the movie done playing I want to display the jpg. I am new to Actionscript world, please provide codes how to do it. Some problems I am facing is - the SWF movie plays for ever (loop is default). That is why I have a timer object to stop after some seconds and load and display the jpg. The movie is stopping at given seconds but jpg is not displaying. here is the codes i have so far -
//Test Program
 
 
package
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.URLRequest;
	import flash.text.*;
	import flash.utils.*;
	
	
	public class ScriptTest extends Sprite{
		
		private static var name:String = "VirtualTest";
		private static var introMovieFileName:String = "INTRO.swf";
		private static var backgroundImage:String = "BACKGROUND.jpg";
		private static var timeframe:int = 10;//Play for this many seconds
		private static var timeIntroLast:int = 13500;
		private var loader:Loader;
		private var imageLoader:Loader;
		
		//private var instance:Object;
	
		
		public function ScriptTest(){
			
			//instance = this;
			
			var timer:Timer = new Timer(timeIntroLast);
			timer.addEventListener(TimerEvent.TIMER, onTimer);
			timer.start();
			
						
			//Load Module.swf
			loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoader_Complete);
			loader.load(new URLRequest(introMovieFileName));
			addChild(loader);
		}
	
		private function onLoader_Complete(e:Event):void{
			
			
			e.target.content.x = -375;
			e.target.content.y = -150;
		}
		
		private function onTimer(e:Event): void{
			
			loader.close();
			loader.unload();
			loader.removeChildAt(0);
			
			//Load image and display
			imageLoader = new Loader();
			imageLoader.load(new URLRequest(backgroundImage));
			stage.addChild(imageLoader);
		
		}
		
		
		
		
	}
}

Open in new window

0
openujs
Asked:
openujs
1 Solution
 
ugebCommented:
Hi,

A few things to try.   Change

 stage.addChild(imageLoader);

to

addChild(imageLoader);


Second, place your timer code in the function
onLoader_Complete

That way it will only start counting after the clip is fully loaded.

Third,  instead of removing the loader child, remove the loader from the display list:

removeChild(loader);

And, if you'll not need this movie again, then delete it after removing it by setting loader=null and letting the garbage collector sweep it away.

Are you certain your background image is in the same directory as the swf?  Is the name correct?  Are you running in a case sensitive environment?


0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now