The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 3 of 3

Thread: Controlling loaded swf files help

  1. #1

    Controlling 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?

  2. #2
    I 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...

  3. #3
    Thanks for the reply. I'm looking into it. Haven't quite got the philosophy of AS3 yet.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012