A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [CS3] [AS3] Loading one movie after another

  1. #1
    Member
    Join Date
    Apr 2008
    Location
    Indianapolis, IN
    Posts
    75

    [CS3] [AS3] Loading one movie after another

    I know this question has been answered in several forms on this forum, but I haven't been able to find an answer that works in my case.

    I have 6 movies that I want to load in to a swf and I want movie #2 to start playing when movie #1 is done, and so forth. I have tried this code, but it just replays the first movie again and again.
    Code:
    var tut01:tutorial01 = new tutorial01();
    var target:DisplayObject;
    var startTime:Number;
    var duration:Number;
    
    addChild(tut01);
    tut01.play();
    
    function clipDuration (duration:Number):void {
    	tut01.duration = duration;
    	target.addEventListener(Event.ENTER_FRAME, enterFrameListener);
    }
    
    function enterFrameListener (e:Event):void {
    	var elapsed:Number = getTimer()-startTime;
    	var percentDone:Number = elapsed/duration;
    	if (percentDone == 1) {
    		gotoAndPlay("tutorial02");
    		target.removeEventListener(Event.ENTER_FRAME, enterFrameListener);
    	}
    }

    I have created six frames in the swf that is loading these movies (one for each movie), that's what the 'tutorial02' is referring to.

    Thanks for any help!

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Can you post your FLA's or zip file somewhere? I will help but I don't feel like recreating all this in flash :d

  3. #3
    Member
    Join Date
    Apr 2008
    Location
    Indianapolis, IN
    Posts
    75
    Thanks for your help! I have uploaded a 'dummy' version of what I'm trying to do.
    Attached Files Attached Files

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Here is one way of doing it, let me know if this make sense.

  5. #5
    Member
    Join Date
    Apr 2008
    Location
    Indianapolis, IN
    Posts
    75
    Thanks for your help. That kind of works...they do play one right after the other, but it looks like it starts playing the next clip a few seconds in instead of from the beginning. Any ideas?

  6. #6
    The Metamorphic Mutant Mystique_MHz's Avatar
    Join Date
    Mar 2002
    Location
    Orlando, FL
    Posts
    218
    I had this exact same problem. I found my solution at another flash board.. here's the code you need. Please don't ask me how to explain it to you.. thus it's a bit over my head.

    Create a new flash movie at 25 frames per second.. in the first keyframe insert this code:

    // **code starts
    function ClipSLoader(target_mc) {
    var _ts = this;
    _ts.mcContainer = target_mc.createEmptyMovieClip("theContainer", 0);
    _ts.onClipEnd();
    }
    ClipSLoader.prototype.checkIfEnd = function() {
    var _ts = this;
    var _mcc = _ts.mcContainer;
    if (_mcc.getBytesLoaded() == _mcc.getBytesTotal() && _mcc.getBytesTotal()>4) {
    if (_mcc._currentframe == _mcc._totalframes) {

    _ts.onClipEnd();

    }
    }
    };
    ClipSLoader.prototype.onClipEnd = function() {
    // default event handler
    };
    ClipSLoader.prototype.loadClip = function(clipToLoad) {
    var _ts = this;
    _ts.mcContainer.loadMovie(clipToLoad);
    trace("clipToLoad is "+clipToLoad);
    _ts.checkIfEndingID = setInterval(_ts, "checkIfEnd", 40);
    };

    myLoader = new ClipSLoader(_root);

    var mcS_array = new Array(["TVExhibits.swf"], ["Part03.swf"], ["DataEntry04.swf"]);

    var mcIndex = 0;

    myLoader.loadClip(mcS_array[0]);

    myLoader.onClipEnd = function() {
    // load the next swf;
    if (mcIndex<mcS_array.length-1) {
    ++mcIndex;
    myLoader.loadClip(mcS_array[mcIndex]);
    clearInterval(this.checkIfEndingID);
    //mcIndex++;
    } else {
    mcS_array = null;
    clearInterval(this.checkIfEndingID-1);
    myLoader.loadClip(mcS_array[mcIndex]);

    }
    };
    // **code ends



    You must replace this info :var mcS_array = new Array(["TVExhibits.swf"], ["Part03.swf"], ["DataEntry04.swf"]); with the name of your .swf files you want to load in sequential order.

  7. #7
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    That is AS 2.0 - he is using AS 3.0. You may have to put a stop() in the .swf files you are loading so they do not play until you tell them to.

  8. #8
    Member
    Join Date
    Apr 2008
    Location
    Indianapolis, IN
    Posts
    75
    Thanks Mystique and sstadler. I thought that looked like AS 2.0...I'll try and see if I can convert it to AS 3.0 and get it to work. I'll let you all know how it turns out.

    (oh and, I'm a 'she' not a 'he')

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center