0
votes

I am developing an IOS app using Adobe AIR, Flash and ActionScript 3 and I have divided sections up into separate SWF files. I have successfully gotten the app to load external SWFs and execute their ActionScript using the following code:

var proloader:ProLoader = new ProLoader();
proloader.load(new URLRequest("file.swf"), new LoaderContext(false, ApplicationDomain.currentDomain, null));
addChild(proloader);

Now, I would like to add a reset button that allows the user to return to the start of the first SWF from any other SWF file to restart the app. Unfortunately, it seems that whenever I try to load a SWF that has previously been loaded, nothing happens. I have read that unloading and reloading SWFs is not permitted on IOS and the fact that you are limited to one ApplicationDomain on IOS makes things difficult. However, I am still thinking there must be some workaround. I'd be okay with not ever unloading the external SWFs if that is the only way, but I still can't figure out a way to return to a SWF that was previously loaded.

Does anyone know of a way to return to a SWF that was previously loaded in IOS with Adobe Air?

2

2 Answers

0
votes

You could have a static class that functions as a cache.

The cache might look something like this that I made for a menu system:

package com.rs2014.managers{ import flash.display.MovieClip; import flash.utils.Dictionary; import flash.events.Event; import flash.events.EventDispatcher;

import com.events.MenuManagerEvent;
import com.menus.MenuBase;
import com.components.MenuLoader;
import com.MenuIdents;


public class MenuManager extends EventDispatcher
{

    private static var instance:MenuManager
    private static var allowInstantiation:Boolean = true;

    public static function getInstance():MenuManager
    {
        if(!instance)
        {
            instance = new MenuManager();
            allowInstantiation = false;
        }

        return instance
    }

    private const MAX_MENUS:uint = 8;

    private var menuCache:Dictionary = new Dictionary()

    public function MenuManager()
    {
        if(!allowInstantiation)
        {
            throw(new Error("please use the getInstance() method to obtain a handle to this singleton"));
        }
    }

    public function getMenu(menu:String):void
    {
        if(menuCache[menu])
        {
            //This pulls from the cache if it's already been loaded before
            dispatchMenu(null, menuCache[menu]);
        }
        else
        {
            //MenuLoader is a simple wrapper for Loader
            var newLoader:MenuLoader = new MenuLoader();
            menuCache[menu] = newLoader;
            newLoader.addEventListener(Event.COMPLETE, dispatchMenu);
            newLoader.source = menu;
            //trace("setting up loader with source = "+menu);
        }
    }

    private function dispatchMenu(e:Event = null, menu:MenuBase = null):void
    {
        if(e)
        {
            e.target.removeEventListener(Event.COMPLETE, dispatchMenu);
            //trace(e.target.content);
            //trace(e.target.content as MenuBase);
            menuCache[e.target.source] = menu = e.target.content as MenuBase;
            //trace(menu);

        }

        if(!menu)
        {
            throw(new Error("MenuManager Error: dispatchMenu called without menu to dispatch"));
        }
        this.dispatchEvent(new MenuManagerEvent(MenuManagerEvent.MENU_READY, menu))

    }



}

}

0
votes

I was able to solve the problem of reloading SWF's w/o ABC (no code!), I explain it all on my blog (http://www.eqsim.com/blog/?p=400) but also simply give the code on StackOverflow: Load and reload external SWF in AIR for iOS wf-in-air-for-ios/22046009#22046009

Now Adobe has a solution for separating code from the SWF, and loading the SWF externally. However, we addressed it prior to AIR 3.5 by making a class for the code only, then loading the SWF and in the code class, setting a link to the loaded SWF. When we needed to update to 4.0, the SWF reloading, even pure SWF assets, was not working in all situations, so we plugged away to find the solution I reference above.