Results 1 to 3 of 3
-
April 30th, 2010, 04:40 AM #13Registered User
postsControlling loaded swf files help
Hello, I’m trying to create a universal fla file (shell.fla) in which I can load any swf file and control it from buttons in the shell itself. The buttons being play, pause, rewind, magnify etc. I’ve done all this in AS2 and now I have to do it in AS3. See my website http://www.eudv.de/Pages/flash.html - E-Training - Motor to get a better idea of what I mean.
The shell file has three buttons so far with instances called playMovie, stopMovie changeMovie and a dynamic text field - movieNumber. It is bound to the class Shell. The swf files to be loaded are numerical 1.swf, 2.swf, 3.swf etc. If I can get playMovie, stopMovie to work I can then do the rest.
Here is my code so far for the class Shell.as:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
public class Shell extends MovieClip {
var movie:MovieClip;
var N:uint;
public function Shell() {
N=0;
// Buttons to control the movieClip instance movie
playMovie.addEventListener(MouseEvent.CLICK, onPlayClick);
stopMovie.addEventListener(MouseEvent.CLICK, onStopClick);
//Button to change movieClip
changeMovie.addEventListener(MouseEvent.CLICK, onChangeClick);
//maybe not necessary?
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function loadHandler(event:Event) {
var movie:MovieClip=event.target.content;
addChild(movie);
movie.stop();
}
private function onChangeClick(event:MouseEvent):void {
N++;
//Dynamic text to show which swf file is running
movieNumber.text=N+".swf";
if (N>0) {
//loads the next swf file
var nextMovie:URLRequest=new URLRequest(N+".swf");
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener(Event .COMPLETE, loadHandler);
swfLoader.load(nextMovie);
}
}
public function onPlayClick(event:MouseEvent):void {
movie.play();
}
public function onStopClick(event:MouseEvent):void {
movie.stop();
}
public function onEnterFrame(event:Event):void {
}
}
}
The problem:
1. How can I kill, unload, removeChild the preceding swf file which has been loaded? When I load a swf file it creates a new loader.
2. On the onPlayClick and onStopClick buttons I get the following error message:
TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.at Shell/onPlayClick()
Has anybody got any ideas please?
-
April 30th, 2010, 05:26 AM #244fatty boom boom
postsI have been doing something very similar myself recently. I made a simple loader class, when the swf is loaded I create a variable to hold that reference and then null the loader for the garbage collector.
var newSWFmc:MovieClip = myEasyLoadClass.getSWF();
myEasyLoadClass = null;
That first line is pretty much what you're doing with the event.target.content part of your script.
Don't know if you noticed, but your Event .COMPLETE should be Event.COMPLETE (no space).Last edited by plumpnation; April 30th, 2010 at 05:32 AM.
no more denturists or truckers please...
-
April 30th, 2010, 12:15 PM #33Registered User
postsThanks for the reply. I'm looking into it. Haven't quite got the philosophy of AS3 yet.

Reply With Quote

Bookmarks