• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

as3 external swf close self

Guest
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

Hi,

After looking through online forums and video tutorials...

I am still faced with errors loading an external swf into my main swf (full stage width).

In my main.swf.....i have several scenes.

On one of those scenes I have an external SWF which loads to the size of my main.swf stage.

That works fine...

BUT

I now want to close the external swf on a button (in my external swf) and go back to one of my scenes in my main.SWF

I have read many forums which talk about dispatchEvent

I have tried these methods and I am still faced with errors.

I just want a button on my external.swf that closes/unloads/removes itself.......so the user can continue in the MAIN.SWF after they have played EXTERNAL.SWF.

in actionscript 2 this was a doddle,

in as3 it is an unnecessary pain in my rectum

sorry if I have missed much out

any help would be much appreciated

jayquery

TOPICS
ActionScript

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 02, 2014 Apr 02, 2014

Try changing the main file loader code to more like the following (blue is new😞

var defaultSWF:URLRequest = new URLRequest("gametestG.swf");

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.load(defaultSWF);

function loaderCompleteHandler(evt:Event):void {
    MovieClip(evt.target.content).addEventListener("closeChild", onChildClose);
    addChild(loader);
}

function onChildClose(event:Event):void {
    loader.unloadAndStop();
    r

...

Votes

Translate

Translate
LEGEND ,
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

It would be appropriate to follow the direction you say you found where the swf dispatches an event when it wants to be closed.  When you load the swf you assign an event listener to it in the main file for the event that it will generate.  You need to do this after the swf has completely loaded.  Then just have the swf dispatch said event via the button to close it and the main file should hear it and process unloading the Loader that brought the swf in.

If you show the code that you tried that didn't producethe desired result it should help to get it to work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

I have this code on my main.SWF scene....

var Xpos:Number = 800;

var Ypos:Number= 600;

var swf:MovieClip;

var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest("gametestG.swf");

 

loader.load(defaultSWF);

addChild(loader);

childSwif.addEventListener("closeChild", onChildClose);

function onChildClose(event:Event):void

{

    removeChild(childSwif);

    childSwif.unloadAndStop();

  

}

that loads to my stage size which is all good

on my external swf I had ....

back_btn.addEventListener(MouseEvent.CLICK,unloadSelf);

function unloadSelf (e:MouseEvent){

dispatchEvent("closeChild");

}

Thanks for the reply

jayquery

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2014 Apr 02, 2014

Copy link to clipboard

Copied

Try changing the main file loader code to more like the following (blue is new😞

var defaultSWF:URLRequest = new URLRequest("gametestG.swf");

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
loader.load(defaultSWF);

function loaderCompleteHandler(evt:Event):void {
    MovieClip(evt.target.content).addEventListener("closeChild", onChildClose);
    addChild(loader);
}

function onChildClose(event:Event):void {
    loader.unloadAndStop();
    removeChild(loader);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 30, 2016 Oct 30, 2016

Copy link to clipboard

Copied

Can you help me solve this problem..?

I have a dispatchEvent  to

I put a button on my external.swf that closes/unloads/removes itself.......so the user can continue in the MAIN.SWF after load the EXTERNAL.SWF.

I have tried these methods and the child file is still not close/unload.

I have this code on my main.SWF scene....

btnNKa.addEventListener(MouseEvent.CLICK, loadNK1);

var myLoaderNK:Loader = new Loader();

function movieLoaded(event:Event):void {

    myLoaderNK.x=0;

    myLoaderNK.y=0;

    myLoaderNK.scaleX=1;

    myLoaderNK.scaleY=1;

stage.addChild(myLoaderNK);

myLoaderNK.content.addEventListener("killMe", killLoadedClip);

}

function killLoadedClip(event:Event):void{

event.target.removeEventListener("killMe", killLoadedClip)

stage.removeChild(myLoaderNK);

myLoaderNK.unload();

}

function loadNK1(MouseEvent):void {

    var urlNK1:URLRequest=new URLRequest("sampel_file.swf");

    myLoaderNK.load(urlNK1);

    stage.addChild(myLoaderNK);

}

And this code on my child SWF (sampel_file.SWF) scene....

tmbl_exit.addEventListener(MouseEvent.CLICK, fl_close);

function fl_close(event:MouseEvent):void

{

    dispatchEvent(new Event("killMe", true));

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

You do not appear to have anything that calls the movieLoaded function.  See the very first line of blue code in my example above.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

its workin.. thank u very much..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2016 Oct 31, 2016

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines