Copy link to clipboard
Copied
Hi,
Some months ago I could use the "Click to Load/Unload SWF" code snippet for iOS apps. It was just this:
stop();
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import fl.display.ProLoader;
var fl_ProLoader:ProLoader;
//This variable keeps track of whether you want to load or unload the SWF
var fl_ToLoad:Boolean = true;
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
if(fl_ToLoad)
{
fl_ProLoader = new ProLoader();
fl_ProLoader.load(new URLRequest("1bis.swf"));
addChild(fl_ProLoader);
}
else
{
fl_ProLoader.unload();
removeChild(fl_ProLoader);
fl_ProLoader = null;
}
{
gotoAndStop(5);
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad = !fl_ToLoad;
}
But now it doesn't work when I upload my app for TestFlight. It stays unresponsive.
Any idea what's going on?
Best,
change this:
var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
to:
var lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
Copy link to clipboard
Copied
did you add 1bis.swf to your included files?
do you have any as code in 1bis.swf?
Copy link to clipboard
Copied
Hi Kglad,
Yes, I have a 1bis.swf on my included files and yes, there is some AS code in 1bis.swf to load other swfs with the same type of Code Snippet.
This is the as on 1bis.swf
stop();
button_a.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import fl.display.ProLoader;
var fl_ProLoader:ProLoader;
var fl_ToLoad:Boolean = true;
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
if(fl_ToLoad)
{
fl_ProLoader = new ProLoader();
fl_ProLoader.load(new URLRequest("2ing.swf"));
addChild(fl_ProLoader);
}
else
{
fl_ProLoader.unload();
removeChild(fl_ProLoader);
fl_ProLoader = null;
}
{
gotoAndStop(5);
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad = !fl_ToLoad;
}
button_b.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_2);
import fl.display.ProLoader;
var fl_ProLoader_2:ProLoader;
var fl_ToLoad_2:Boolean = true;
function fl_ClickToLoadUnloadSWF_2(event:MouseEvent):void
{
if(fl_ToLoad_2)
{
fl_ProLoader_2 = new ProLoader();
fl_ProLoader_2.load(new URLRequest("2esp.swf"));
addChild(fl_ProLoader_2);
}
else
{
fl_ProLoader_2.unload();
removeChild(fl_ProLoader_2);
fl_ProLoader_2 = null;
}
{
gotoAndStop(5);
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_2 = !fl_ToLoad_2;
}
button_c.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_3);
import fl.display.ProLoader;
var fl_ProLoader_3:ProLoader;
var fl_ToLoad_3:Boolean = true;
function fl_ClickToLoadUnloadSWF_3(event:MouseEvent):void
{
if(fl_ToLoad_3)
{
fl_ProLoader_3 = new ProLoader();
fl_ProLoader_3.load(new URLRequest("2port.swf"));
addChild(fl_ProLoader_3);
}
else
{
fl_ProLoader_3.unload();
removeChild(fl_ProLoader_3);
fl_ProLoader_3 = null;
}
{
gotoAndStop(5);
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_3 = !fl_ToLoad_3;
}
button_d.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_4);
import fl.display.ProLoader;
var fl_ProLoader_4:ProLoader;
var fl_ToLoad_4:Boolean = true;
function fl_ClickToLoadUnloadSWF_4(event:MouseEvent):void
{
if(fl_ToLoad_4)
{
fl_ProLoader_4 = new ProLoader();
fl_ProLoader_4.load(new URLRequest("2fran.swf"));
addChild(fl_ProLoader_4);
}
else
{
fl_ProLoader_4.unload();
removeChild(fl_ProLoader_4);
fl_ProLoader_4 = null;
}
{
gotoAndStop(5);
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_4 = !fl_ToLoad_4;
}
button_e.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_5);
import fl.display.ProLoader;
var fl_ProLoader_5:ProLoader;
var fl_ToLoad_5:Boolean = true;
function fl_ClickToLoadUnloadSWF_5(event:MouseEvent):void
{
if(fl_ToLoad_5)
{
fl_ProLoader_5 = new ProLoader();
fl_ProLoader_5.load(new URLRequest("2ital.swf"));
addChild(fl_ProLoader_5);
}
else
{
fl_ProLoader_5.unload();
removeChild(fl_ProLoader_5);
fl_ProLoader_5 = null;
}
{
gotoAndStop(5);
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad_5 = !fl_ToLoad_5;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi Kglad,
Thanks for the link. I understand now why the code snippet does not work on iOS. The problem is I can´t figure out how to load/unload an swf by clicking a button.
Is there a code snippet to do that on iOS? Instead of:
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import fl.display.ProLoader;
var fl_ProLoader:ProLoader;
var fl_ToLoad:Boolean = true;
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
if(fl_ToLoad)
{
fl_ProLoader = new ProLoader();
fl_ProLoader.load(new URLRequest("1bis.swf"));
addChild(fl_ProLoader);
}
else
{
fl_ProLoader.unload();
removeChild(fl_ProLoader);
fl_ProLoader = null;
}
// Toggle whether you want to load or unload the SWF
fl_ToLoad = !fl_ToLoad;
}
Best,
Copy link to clipboard
Copied
use:
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import flash.display.Loader
var loader:Loader=new Loader()
var _urlRequest:URLRequest = new URLRequest(“mySecondarySwf.swf”);
var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
if(!loader.stage)
{
loader.load(_urlRequest, lc);
addChild(loader);
}
else
{
loader.unloadAndStop();
removeChild(loader);
}
{
gotoAndStop(5);
}
}
Copy link to clipboard
Copied
Hi Kglad,
Thanks for your advice. I am trying but I keep getting this error message:
"1120: access of undefined property lc."
Any advice?
Best,
Copy link to clipboard
Copied
change this:
var _lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
to:
var lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
Copy link to clipboard
Copied
Got it!
Thanks a lot for your help.
The bad news are that I’m having difficulties when trying to load swfs which are in subfolders. I can load and swf which is inside a subfolder but when I try loading an swf which is inside the next subfolder level I get this:
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
From the main swf I go like this without issues:
[SWF] 1.swf - 3821 bytes after decompression
[SWF] 1bis.swf - 4497 bytes after decompression
[SWF] 2esp.swf - 14339 bytes after decompression
[SWF] notaspiano/b.swf - 13075 bytes after decompression
[SWF] notaspiano/b.swf - 13075 bytes after decompression
But when I try to load next swf: “notaspiano/esp/notasesp.swf”
I get this error:
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
Can you help me with this?
Best,
Copy link to clipboard
Copied
you have an incorrect path and/or file name.
attach a screenshot showing the directory that contains the main (ie, the one with the loader) swf and html and the one that contains notasesp.swf
Copy link to clipboard
Copied
Sorry but I think I don´t know how to create a directory and I don´t use html, just swfs.
What I do is this:
- on 1.swf I have this:
stop();
button_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF);
import flash.display.Loader
var loader:Loader=new Loader()
var _urlRequest:URLRequest = new URLRequest("1bis.swf");
var lc:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
function fl_ClickToLoadUnloadSWF(event:MouseEvent):void
{
if(!loader.stage)
{
loader.load(_urlRequest, lc);
addChild(loader);
}
else
{
loader.unloadAndStop();
removeChild(loader);
}
{
gotoAndStop(5);
}
}
- on 1bis.swf I have this:
stop();
button_b_1.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_b_1);
import flash.display.Loader
var loader_b_1:Loader=new Loader()
var _urlRequest_b_1:URLRequest = new URLRequest("2esp.swf");
var lc_b_1:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
function fl_ClickToLoadUnloadSWF_b_1(event:MouseEvent):void
{
if(!loader_b_1.stage)
{
loader_b_1.load(_urlRequest_b_1, lc_b_1);
addChild(loader_b_1);
}
else
{
loader_b_1.unloadAndStop();
removeChild(loader_b_1);
}
{
gotoAndStop(5);
}
}
- on 2esp.swf I have this:
stop();
{
SoundMixer.stopAll();
}
button_2_esp_2.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_2_esp_2);
import flash.display.Loader
var loader_2_esp_2:Loader=new Loader()
var _urlRequest_2_esp_2:URLRequest = new URLRequest("notaspiano/b.swf");
var lc_2_esp_2:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
function fl_ClickToLoadUnloadSWF_2_esp_2(event:MouseEvent):void
{
if(!loader_2_esp_2.stage)
{
loader_2_esp_2.load(_urlRequest_2_esp_2, lc_2_esp_2);
addChild(loader_2_esp_2);
}
else
{
loader_2_esp_2.unloadAndStop();
removeChild(loader_2_esp_2);
}
{
gotoAndStop(15);
}
}
- on b.swf I have this:
stop();
{
SoundMixer.stopAll();
}
button_1_esp_3.addEventListener(MouseEvent.CLICK, fl_ClickToLoadUnloadSWF_1_esp_3);
import flash.display.Loader
var loader_1_esp_3:Loader=new Loader()
var _urlRequest_1_esp_3:URLRequest = new URLRequest("notaspiano/esp/notasesp.swf");
var lc_1_esp_3:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
function fl_ClickToLoadUnloadSWF_1_esp_3(event:MouseEvent):void
{
if(!loader_1_esp_3.stage)
{
loader_1_esp_3.load(_urlRequest_1_esp_3, lc_1_esp_3);
addChild(loader_1_esp_3);
}
else
{
loader_1_esp_3.unloadAndStop();
removeChild(loader_1_esp_3);
}
{
gotoAndStop(10);
}
}
I hope it´s not confusing.
Best,
Copy link to clipboard
Copied
use
"./notaspiano/esp/notas_esp.swf"
Copy link to clipboard
Copied
Hi Kglad,
Thanks a lot for your help. Did what you said but I´m still having some issues.
Works OK in Device debugging in interpreter mode. I can go back and forth through the swfs.
But when tested from TestFlight I can go all the way down to "./notaspiano/esp/notas_esp.swf" just once because if I go one or two steps back then I cannot go down again.
I’m loading the swfs this way:
- from 1.swf I call
"1bis.swf"
- from 1bis.swf I call
"2esp.swf"
- from 2esp.swf I call
"notaspiano/b.swf"
- from b.swf I call
"./notaspiano/esp/notas_esp.swf"
Any advice?
Best,
Copy link to clipboard
Copied
i don't understand, "But when tested from TestFlight I can go all the way down to "./notaspiano/esp/notas_esp.swf" just once because if I go one or two steps back then I cannot go down again."
Copy link to clipboard
Copied
I mean that when testing from TestFlight the swfs don´t reload. Which is said on the link you first gave me:
Packaging and loading multiple SWFs in AIR apps on iOS
SWF Reloading
In AIR apps on iOS running in AOT mode there is a problem when a SWF is reloaded. Therefore reloading a SWF will not be allowed for AIR apps for iOS in AOT mode and attempting to do so will result in following error:
Error 3764: Reloading a SWF is not supported on this operating system
Note:If a SWF is accessed using different URLs like different paths referring to the same SWF, or using app:// and app-storage:// URI schemes to access the same SWF, then the two SWFs would be considered different and the SWF will be re-loaded. However, the behavior in such cases would be undefined.
Is there a workaround for this? I need users to be able to load, unload and reload several swfs at different levels as many times as they want on iOS. And all these swfs have some AS3 on them.
As you already help my clarifying the main issue of this thread and I already marked as correct your answer I started a new thread for this issue:
Is there a solution or workaround to "SWF load, unload and Reload on iOS" issue?
I hope you can give it a look.
Best,
Find more inspiration, events, and resources on the new Adobe Community
Explore Now