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

Home_btn to reload iOS app is not working???

Explorer ,
Aug 10, 2016 Aug 10, 2016

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.

TOPICS
ActionScript
2.8K
Translate
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

Community Expert , Aug 17, 2016 Aug 17, 2016

attach a screenshot of your air for ios settings panel that shows your included files.

Translate
Community Expert ,
Aug 10, 2016 Aug 10, 2016

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.

Translate
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
Explorer ,
Aug 10, 2016 Aug 10, 2016

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.

Translate
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
Community Expert ,
Aug 10, 2016 Aug 10, 2016

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.

Translate
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
Explorer ,
Aug 11, 2016 Aug 11, 2016

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.

Translate
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
Community Expert ,
Aug 11, 2016 Aug 11, 2016

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.

}

}

Translate
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
Explorer ,
Aug 12, 2016 Aug 12, 2016

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.

Translate
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
Community Expert ,
Aug 12, 2016 Aug 12, 2016

if(!this['go_'+(i+1)].hasEventListener(MouseEvent.CLICK,load_levelF)){

should be

if(!this['go_'+(i+1)].hasEventListener(MouseEvent.CLICK)){

Translate
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
Explorer ,
Aug 12, 2016 Aug 12, 2016

Tnx again

Translate
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
Community Expert ,
Aug 12, 2016 Aug 12, 2016

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
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
Explorer ,
Aug 13, 2016 Aug 13, 2016

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????

Translate
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
Community Expert ,
Aug 13, 2016 Aug 13, 2016

use a mousedown event for touch devices, instead of a click.

Translate
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
Explorer ,
Aug 13, 2016 Aug 13, 2016

oke i will try tnx

Translate
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
Explorer ,
Aug 14, 2016 Aug 14, 2016

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);

}

}

Translate
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
Community Expert ,
Aug 14, 2016 Aug 14, 2016

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....

Translate
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
Explorer ,
Aug 15, 2016 Aug 15, 2016

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.

Translate
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
Community Expert ,
Aug 15, 2016 Aug 15, 2016

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:

Screenshot - 8_15_2016 , 7_32_07 AM.png

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);

}

}

Translate
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
Explorer ,
Aug 17, 2016 Aug 17, 2016

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.

Translate
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
Community Expert ,
Aug 17, 2016 Aug 17, 2016

what doesn't work?

Translate
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
Explorer ,
Aug 17, 2016 Aug 17, 2016

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.

Translate
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
Community Expert ,
Aug 17, 2016 Aug 17, 2016

attach a screenshot of your air for ios settings panel that shows your included files.

Translate
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
Explorer ,
Aug 17, 2016 Aug 17, 2016

scherm1a.jpg

Translate
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
Explorer ,
Aug 17, 2016 Aug 17, 2016

Scherm2a.jpg

Translate
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
Community Expert ,
Aug 17, 2016 Aug 17, 2016

that looks good.

now click debug>debug movie>on device via usb

Screenshot - 8_17_2016 , 11_27_39 AM.png

click go_1 after the debug panel loads and your app opens.  any error message?

Translate
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
Explorer ,
Aug 17, 2016 Aug 17, 2016

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.

Translate
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