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
each level swf can direct the main swf to unload the level swf, but because your main swf is not loaded, i don't think you want to load it into itself.
Copy link to clipboard
Copied
hello,
tnx for reply..
the structure of my app is: before I open a new level the previous level has been unloaded.
But now I want back to start the whole app again with new levels SWF's.
First I think I must close the app.But I don't know how to do this. Because the NativeApplication.
NativeApplication.exit (); didn't work. Sorry i didn't understand it at all. I hope you can help me.
Copy link to clipboard
Copied
you can reload the level swfs and they should restart from the beginning. i'm not sure what's in your main swf that needs to be 'reset', but you should encode that explicitly.
Copy link to clipboard
Copied
Hello,
In the level1 swf the code is on the last frame:
stop();
var App_Timer:Timer = new Timer(500,1);
App_Timer.addEventListener(TimerEvent.TIMER_COMPLETE, startApp);
App_Timer.start();
function startApp(event:TimerEvent):void {
dispatchEvent(new Event("LEVEL_1",true));
}
In the main swf the code is:
go_1.addEventListener(MouseEvent.CLICK, level_1);
function level_1(event: MouseEvent) {
var loader1 = new Loader;
var loaderContext1: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
var file1: File = File.applicationDirectory.resolvePath("level1.swf");
loader1.load(new URLRequest(file1.url), loaderContext1);
dispatchEvent(new Event("LEVEL_1", true));
addChild(loader1);
loader1.addEventListener("LEVEL_1", finishLevel1);
function finishLevel1(event: Event): void {
loader1.parent.removeChild(loader1);
loader1.unloadAndStop();
go_1.visible = false;
go_2.visible = true;
etc.
Copy link to clipboard
Copied
i'm not sure why you need a .5 second delay before dispatching that event in your level1 swf, but that won't cause a problem.
in you main swf, you're nesting named functions. never nest named functions.
it also appears you may be using more than one loader. ie, one loader for each level. you only need more than one loader if you need to load more than one level at any one time. that's unlikely so, use one loader and don't make it local to a function.
you're also using the file class to load a swf which is unnecessary and there are several other problems with your code.
try:
last frame of the main timeline of your level1 swf:
this.parent.dispatchEvent(new Event('level_completeE',true));
in your main swf:
var current_level:int = 1;
var num_levels:int = 10; // use the total number of your levels
var loader:Loader = new Loader();
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.CLICK,load_levelF)){
this['go_'+(i+1)].level = i+1; // assuming these are movieclips
this['go_'+(i+1)].addEventListener(MouseEvent.CLICK,load_levelF);
}
}
this['go_'+n)].visible = true;
}
function load_levelF(e:MouseEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'));
}
function level_completeF(e:Event):void{
if(loader.content){
loader.unloadAndStop();
}
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
// all levels completed. reset current_level to 1, if that's what you want.
}
}
Copy link to clipboard
Copied
Tnx a lot kglad,
I have studied your code and i have also changed my own code into your code.
It is much better.
i only have changed the code:this['go_'+n)].visible = true; into: this['go_'+n].visible = true;
i hope it's good.
But i have also the next error:
ArgumentError: Error #1063: Argument count mismatch on flash.events::EventDispatcher/hasEventListener(). Expected 1, got 2.
at main_fla::MainTimeline/goF()[main_fla.MainTimeline::frame1:33]
at main_fla::MainTimeline/frame1()[main_fla.MainTimeline::frame1:28]
[UnloadSWF] main.swf
Testfilm beëindigd.
frame1:33 = if(!this['go_'+(i+1)].hasEventListener(MouseEvent.CLICK,load_levelF)){
frame1:28 =goF(current_level);
I hope you can help me again.
Copy link to clipboard
Copied
if(!this['go_'+(i+1)].hasEventListener(MouseEvent.CLICK,load_levelF)){
should be
if(!this['go_'+(i+1)].hasEventListener(MouseEvent.CLICK)){
Copy link to clipboard
Copied
Tnx again
Copy link to clipboard
Copied
you're welcome.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
Hello,
I'm desperate again. the code above works very good on laptop.
But not on the Ipad.
I have included all the level.SWF's into the main.SWF. I have also published the last version of all
the levels.SWF. What can be the problem???
I hope someone can help me????
Copy link to clipboard
Copied
use a mousedown event for touch devices, instead of a click.
Copy link to clipboard
Copied
oke i will try tnx
Copy link to clipboard
Copied
hello ,
it's terrible but i'm on the forum again.
according to your response
I tried several things.
But it doesn't work either.
I am simply trying for a long time to make a HOME button to reload my game again.
But to no avail.
btw: mouseCLICK works in the level.SWF's.
but not in the code below.
my code is:
import......
import flash.events.TouchEvent;
import flash.events.TouchEventIntent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
// all variabelen etc.
var current_level:int = 1;
var num_levels:int = 10;
var loader:Loader = new Loader();
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(TouchEvent.TOUCH_TAP)){
this['go_'+(i+1)].level = i+1;
this['go_'+(i+1)].addEventListener(TouchEvent.TOUCH_TAP,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:TouchEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'));
addChild(loader);
}
function level_completeF(e:Event):void{
if(loader.content){
loader.unloadAndStop();
}
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
use:
var current_level:int = 1;
var num_levels:int = 10; // use the total number of your levels
var loader:Loader = new Loader();
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)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+n)].visible = true;
}
function load_levelF(e:MouseEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'));
}
function level_completeF(e:Event):void{
if(loader.content){
loader.unloadAndStop();
}
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
// all levels completed. reset current_level to 1, if that's what you want.
}
}
p.s. what's that first line: import....
Copy link to clipboard
Copied
tnx again for reply. I very thankful of that.
but it also doesn't work.
//I included all 10 levels to main.SWF. I checked all movieClips and Levels.
//it works great on laptop.(with mouse.click) when i change the for loop(var i:int=1;i<num_levels;i++) into i:int=0;?????
//but NOT on ipad. (also with mouse.down)
//movieClips with MOUSE.CLICK separately works great on ipad.
//with the code movieclip.addEventListener(MouseEvent.CLICK,load_levelF);
//but not in for loop???????
//I do not understand the cause.
My whole code now:
stop();
import flash.display.MovieClip
import flash.events.EventDispatcher;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream
import flash.events.Event;
import flash.display.Loader;
import flash.events.MouseEvent;
var go_1:MovieClip;
var go_2:MovieClip;
var go_3:MovieClip;
var go_4:MovieClip;
var go_5:MovieClip;
var go_6:MovieClip;
var go_7:MovieClip;
var go_8:MovieClip
var go_9:MovieClip;
var go_10:MovieClip;
var current_level:int = 1;
var num_levels:int = 10;
var loader:Loader = new Loader();
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=1;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)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:MouseEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'));
addChild(loader);
}
function level_completeF(e:Event):void{
if(loader.content){
loader.unloadAndStop();
}
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
//I hope you (or somebody)can see the solution.
//I don't.
Copy link to clipboard
Copied
you're correct that i:int=1 should be i:int=0.
try the following and make sure your level swf's are added to the included files panel:
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_level:int = 1;
var num_levels:int = 10;
var loader:Loader = new Loader();
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)].addEventListener(MouseEvent.MOUSE_DOWN,load_levelF);
}
}
this['go_'+ n].visible = true;
}
function load_levelF(e:MouseEvent):void{
loader.load(new URLRequest('level'+MovieClip(e.currentTarget).level+'.swf'));
addChild(loader);
}
function level_completeF(e:Event):void{
if(loader.content){
loader.unloadAndStop();
}
current_level++;
if(current_level<=num_levels){
goF(current_level);
} else {
current_level=1;
goF(current_level);
}
}
Copy link to clipboard
Copied
hello i'm on the forum again. Pfff.. sorry for that.
to oversee the problem:
i have created a small mainSWF within only the main AS3code (above) with on the stage
3 movieClips.(go_1,go_2,go_3).
Within the mainSWF i have included 3 levelSWF's with only the the as3code:
this.parent.dispatchEvent(new Event('level_completeE',true));
on the stage a simple figure each level.
the same conclusion as above: on the laptop it works great.
on the ipad the movieclip doesn't work.
do you know a solution?
i hope you (or someone else) can help me again.
Copy link to clipboard
Copied
what doesn't work?
Copy link to clipboard
Copied
hello,
the movieclip go_1 doesn't work on the ipad.
when you touch the movie clip nothing happens
.(the mouse(down)_function )on the computer it works very good.
a mouse function separately (not in a for loop )is not a problem on the ipad.
tnx for reply.
Copy link to clipboard
Copied
attach a screenshot of your air for ios settings panel that shows your included files.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
that looks good.
now click debug>debug movie>on device via usb
click go_1 after the debug panel loads and your app opens. any error message?
Copy link to clipboard
Copied
Wachten op verbinding door speler...
[SWF] main1.swf - 3095635 bytes na decompressie
Error: Error #3747: Multiple application domains are not supported on this operating system.
at main1_fla::MainTimeline/load_levelF()[main1_fla.MainTimeline::frame1:118]
at main1_fla::MainTimeline/load_levelF()
De foutopsporingssessie is beëindigd.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now