0

I'm an as3 newbie, i have one button as name tombol fuctioning to Loading External swf & going to Specific Frame by clicking buttons, this works fine.

import flash.events.MouseEvent;

tombol.addEventListener(MouseEvent.CLICK, tekan2);

function tekan2 (e:MouseEvent):void {

function loadSWF(swfURL){
    var myLoader:Loader = new Loader();
    var mySWF:URLRequest = new URLRequest(swfURL);
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
    myLoader.load(mySWF);

}

function onCompleteHandler(loadEvent:Event){    
    addChild(loadEvent.currentTarget.content);
    loadEvent.currentTarget.content.gotoAndStop(swfFrame);
}

function onProgressHandler(myProgress:ProgressEvent){
    var percent:Number = Math.round(myProgress.bytesLoaded/myProgress.bytesTotal*100);
    trace(percent+"% loaded");
}

var swfFrame:Number=2;
loadSWF("2.swf");

}

This file save as 1.swf and loading file 2.swf go to frame 2, but file 1.swf still loading, so this script loading 2 file swfs(file 2.swf frame 2 loading with file 1.swf appears). How to file 1.swf can unloading same time when I click the button, so just file 2.swf frame appears on stage.

wikan
  • 1

1 Answers1

0

Generally you can cancel a Loader's load operation by using the command close(). Before cancelling you need to make sure that the Loader actually loads data, otherwise an Error will be thrown:

if (myLoader.contentLoaderInfo.bytesLoaded > 0 &&
    myLoader.contentLoaderInfo.bytesLoaded < myLoader.contentLoaderInfo.bytesTotal)
{
    myLoader.cancel();
}

EDIT: You can access the loader of 1.swf by root.loaderInfo. In your function loadSWF you can add the following code to prevent 1.swf from loading further:

if (root.loaderInfo.loader && root.loaderInfo.bytesLoaded > 0 &&
    root.loaderInfo.bytesLoaded < root.loaderInfo.bytesTotal)
{
    root.loaderInfo.loader.cancel();
}

However, I'm not completely sure if you really can cancel the loading process of 1.swf (I have never tried out something like this). Architecture-wise, it would make sense to have a third SWF file, which is your Main SWF, and loads your other SWF files (1.swf and 2.swf, ...). In your main SWF you would need to define the Loader as class variable and not as a local variable as you are currently doing. Whenever you load a SWF, check if another loading operation is in progress and cancel it in that case. Ideally, you would place the button tombol in the Main SWF.

Jan
  • 445
  • 2
  • 12
  • Thanks for your reply Jan, but where I have to put the command `close()` on my script can you show me? and what's your mean : > Before cancelling you need to make sure that the Loader actually loads > data, otherwise an Error will be thrown: And where I have to put your script on my script ? Thank for your explanation before. – wikan May 28 '15 at 02:59
  • Revisiting your origin question my previous answer may not be sufficient enough to help solve your issue. However, I will modify it. Please check the update. – Jan May 28 '15 at 07:17
  • Oke thank .... it is good like that, there should be a third swf. But actually I want to make back and next navigation buttons with different swf file. So I build flash applications but within separated into many fla files. Are there any suggestions how to combine these files by using the navigation key and the next back home. Suppose I make five fla files (1.fla, 2.fla, ... 5.fla), how do I combine them with the back button next home. – wikan May 29 '15 at 04:09