Adobe AIR, IOS, and Multiple SWFs - Returning to a previously loaded SWF

后端 未结 2 1894
臣服心动
臣服心动 2021-01-28 05:59

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

2条回答
  •  感情败类
    2021-01-28 06:30

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

    }

提交回复
热议问题