Copy link to clipboard
Copied
hello again,
I can't find the solution.
I hope someone can help me because I'm desparate.
I have a main-SFW within several levels-SWF's.
Now I want on each level a Home_btn so I can reload the app.
Here is my code in some SWF-level:
Home_btn.addEventListener(MouseEvent.CLICK, go_home);
function go_home(event: MouseEvent) {
var appDomain_1:ApplicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
var context1:LoaderContext = new LoaderContext(false, appDomain_1);
var loader1:Loader = new Loader();
var file1: File = File.applicationDirectory.resolvePath("main.swf");
loader1.load(new URLRequest (file1.url), context1);
addChild(loader1);
}
in the main.SWF the level_SWF's won"t open again.
I have included all SWF's in the MainSWF and the main SWF also.
I hope someone can help me.
attach a screenshot of your air for ios settings panel that shows your included files.
Copy link to clipboard
Copied
oops, we failed to add the loadercontext to the load method:
function load_levelF(e:MouseEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'));
addChild(loader);
}
should be
function load_levelF(e:MouseEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf', loaderContext));
addChild(loader);
}
Copy link to clipboard
Copied
tnx a lot kglad,
when I put the new code from above I get an error: expected 1 argument.
so I change the code into:
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'), loaderContext);
it works great. Thanks for that. the go_1 movie clip is working.
But the main question remains:
How to reload my iOS app????????
} else {
current_level=1;
goF(current_level);
}
is not working.
Error #2044: Unhandled IOErrorEvent:. text=Error #3764: Reloading a SWF is not supported on this operating system.
Copy link to clipboard
Copied
does your go_1 button appear when you expect?
Copy link to clipboard
Copied
yes the button appears on the Ipad. But when you click on it I get when in the debugging screen the error above:
Error #2044: Unhandled IOErrorEvent:. text=Error #3764: Reloading a SWF is not supported on this operating system.
Copy link to clipboard
Copied
that's disappointing but this might be a work-around. you'll need to explicitly stop all streams (eg, sounds & video) in your loaded swfs.
stop();
import flash.display.MovieClip
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.events.Event;
import flash.display.Loader;
import flash.events.MouseEvent;
var current_loader:Loader;
var current_level:int = 1;
var num_levels:int = 10;
var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader.addEventListener('level_completeE',level_completeF);
goF(current_level);
function goF(n:int):void{
for(var i:int=0;i<num_levels;i++){
this['go_'+(i+1)].visible =false;
if(!this['go_'+(i+1)].hasEventListener(MouseEvent.MOUSE_DOWN)){
this['go_'+(i+1)].level = i+1; // assuming these are movieclips
this['go_'+(i+1)].loader = new Loader();
this['go_'+(i+1)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:MouseEvent):void{
current_loader=Loader(e.currentTarget.loader);
if(!e.currentTarget.loaded){
e.currentTarget.loaded=true;
current_loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'),loaderContext);
}
addChild(current_loader);
}
function level_completeF(e:Event):void{
removeChild(current_loader);
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
tnx again kglad,![]()
thanks again you are very helpful. I have only a question about the loader , I got the error:1120
error :1120 actionscript 3 use of undefined property loader.
when I declare the loader. var loader=new Loader(); the error disappears but then
this.parent.dispatchEvent(new Event('level_completeE',true)); on the levels.SWF
didn't work.
There is a conflict with the loader(s). I don't know how to fix that.
Debugging on ipad and computer it doesn't give a report.
Do you know what the problem is?
p.s. i have stopped all actions eg sounds on the last frame levels.
Copy link to clipboard
Copied
use:
stop();
import flash.display.MovieClip
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.events.Event;
import flash.display.Loader;
import flash.events.MouseEvent;
var current_loader:Loader;
var current_level:int = 1;
var num_levels:int = 10;
var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
loader.addEventListener('level_completeE',level_completeF);
goF(current_level);
function goF(n:int):void{
for(var i:int=0;i<num_levels;i++){
this['go_'+(i+1)].visible =false;
if(!this['go_'+(i+1)].hasEventListener(MouseEvent.MOUSE_DOWN)){
this['go_'+(i+1)].level = i+1; // assuming these are movieclips
this['go_'+(i+1)]._loader = new Loader();
this['go_'+(i+1)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:MouseEvent):void{
current_loader=Loader(e.currentTarget._loader);
if(!e.currentTarget.loaded){
e.currentTarget.loaded=true;
current_loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'),loaderContext);
}
addChild(current_loader);
}
function level_completeF(e:Event):void{
removeChild(current_loader);
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
oh oh i'm here again on the forum.
![]()
This code (above) and the code above this code gives the same problem.
The dispatcherEvent doesn't work.
The debug gives no report. not on the ipad. not on the computer.
Copy link to clipboard
Copied
use the trace function to make sure that the loader is dispatching the expected event.
Copy link to clipboard
Copied
hello kglad,
tnx!!
The trace function didn't work. I'm also worried about unloading SWF's.
In connection with the slowness app.
Copy link to clipboard
Copied
why didn't the trace function work? did you use debug>debug movie>via connected usb?
show the trace code and the code near the trace.
Copy link to clipboard
Copied
The dipatcherEvent don't work.
the debugsession gives no reply.
Code debug via usb connected ipad:
Wachten op verbinding door speler...
[SWF] main.swf - 3095615 bytes na decompressie
[SWF] level1.swf - 4905281 bytes na decompressie
Code debug computer:
Bezig verbinding te maken met speler via URL /Users/../Desktop/project/main-app.xml
[SWF] main.swf - 3106786 bytes na decompressie
[SWF] level1.swf - 4945006 bytes na decompressie
code in level1.SWF:
stop();
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;
this.parent.dispatchEvent(new Event('level_completeE',true));
code in main.SWF:
function level_completeF(e:Event):void{
trace("loader works");
removeChild(current_loader);
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
add:
code in level1.SWF:
stop();
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.EventDispatcher;
trace('dispatching event',this);
this.parent.dispatchEvent(new Event('level_completeE',true));
code in main.SWF:
trace('testing trace',this);
function level_completeF(e:Event):void{
trace("loader works");
removeChild(current_loader);
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
tnx!!
Code debug via usb connected ipad now is:
Wachten op verbinding door speler...
[SWF] main.swf - 3095619 bytes na decompressie
[SWF] level1.swf - 4905314 bytes na decompressie
dispatching event [object star_60]
De foutopsporingssessie is beëindigd.
Copy link to clipboard
Copied
why isn't trace code working in your main (loading swf)?
ie, did you this line execute:
trace('testing trace',this);
Copy link to clipboard
Copied
I'm sorry i made a mistake:
Code debug via usb connected ipad:
Wachten op verbinding door speler...
[SWF] main.swf - 3095619 bytes na decompressie
testing trace [object MainTimeline]
[SWF] level1.swf - 4905314 bytes na decompressie
dispatching event [object star_60]
De foutopsporingssessie is beëindigd.
Copy link to clipboard
Copied
your code should be:
kglad wrote:
use:
stop();
import flash.display.MovieClip
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.events.Event;
import flash.display.Loader;
import flash.events.MouseEvent;
var current_loader:Loader;
var current_level:int = 1;
var num_levels:int = 10;
var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
goF(current_level);
function goF(n:int):void{
for(var i:int=0;i<num_levels;i++){
this['go_'+(i+1)].visible =false;
if(!this['go_'+(i+1)].hasEventListener(MouseEvent.MOUSE_DOWN)){
this['go_'+(i+1)].level = i+1; // assuming these are movieclips
this['go_'+(i+1)]._loader = new Loader();
this['go_'+(i+1)]._loader.addEventListener('level_completeE',level_completeF);
this['go_'+(i+1)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:MouseEvent):void{
current_loader=Loader(e.currentTarget._loader);
if(!e.currentTarget.loaded){
e.currentTarget.loaded=true;
current_loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'),loaderContext);
}
addChild(current_loader);
}
function level_completeF(e:Event):void{
removeChild(current_loader);
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
hello kglad tnx a lot voor code.
it works. Tnx for that!
But I have 2 problems:
1-when the last level turn to level1 again, he stops at the last frame of level1 with the "score" of that level.
2-because there isn't a unload function the app becomes slower and slower.
I'm trying now to fix the problems. But I haven't not yet a solution.
Copy link to clipboard
Copied
on the last frame of your loaded swf's, explicitly stop any running processes (eg, enterframe loops).
use:
stop();
import flash.display.MovieClip
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.events.Event;
import flash.display.Loader;
import flash.events.MouseEvent;
var current_loader:Loader;
var current_level:int = 1;
var num_levels:int = 10;
var loaderContext: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
goF(current_level);
function goF(n:int):void{
for(var i:int=0;i<num_levels;i++){
this['go_'+(i+1)].visible =false;
if(!this['go_'+(i+1)].hasEventListener(MouseEvent.MOUSE_DOWN)){
this['go_'+(i+1)].level = i+1; // assuming these are movieclips
this['go_'+(i+1)]._loader = new Loader();
this['go_'+(i+1)]._loader.addEventListener('level_completeE',level_completeF);
this['go_'+(i+1)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:MouseEvent):void{
current_loader=Loader(e.currentTarget._loader);
if(!e.currentTarget.loaded){
e.currentTarget.loaded=true;
current_loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'),loaderContext);
}
MovieClip(current_loader.content).gotoAndPlay(1); // or use gotoAndStop(1)
addChild(current_loader);
}
function level_completeF(e:Event):void{
removeChild(current_loader);
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
hello kglad,
The code works great, tnx a lot!!!!
The only thing that rest is the
problem that the app becomes slower and slower.
There isn't a unload code.
I am afraid that it is the one or the other for iOS.
Copy link to clipboard
Copied
are you stopping all the running processes in the loaded swfs?
Copy link to clipboard
Copied
i have to check my code again!!
is the problem solved when the running processes are stopped??
Copy link to clipboard
Copied
i don't know.
you'll need to find the reason a swf that's removed from the stage is still using cpu.
Copy link to clipboard
Copied
oke tnx!!
Copy link to clipboard
Copied
you're welcome.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more