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

load swf into RAM via an asset manager

Participant ,
Jun 30, 2013 Jun 30, 2013

Hi.

I have an AS3 virtual world and we are continually loading external resources such as swfs and sounds.

A few of my menu screens that take a damn long time to load. Read a tut that said we should load them into RAM using an asset manager.

I'm assuning the asset manager is simply a Class used specifically for loading and unloading graphics, swfs and sounds. So the important part to ask is:

What do they mean by loading into RAM.

I thought all swfs were automatically loaded into RAM ie: cached or in the flash player cache or the browser cache. Or do I have to do it specifically myself with some code. We are importing external files so we thought that was a great idea as they are shared by many games.

btw: RSLs I have read about but I don't understand. I thought my externally loaded files were RSLs (runtime shared libraries) or would I have to do some physical coding do convert them into RSLs.

This is so important because I am not very experienced but I am getting a lot better due to help receied in this forum and my current programmer is leaving me. I have been studying up on As3 and design patterns and I understand basic coding a lot better now.

CHEERS

EDIT: Just read that I am using a http call. - I use urlloader - well that's what you use isn't it or how would you load an external swf. Just read that you can hold the swf as a variable which loads it in RAM and therefore will be available immediately. Know I don't understand anything as I have never read that anywhere.

TOPICS
ActionScript
1.1K
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

LEGEND , Jul 04, 2013 Jul 04, 2013

Hey,

I don't have time now to look into it in any detail but it feels like requests are cache busted. This means that they are loaded every time - not used from cache.

Unless server is configured to non-cache, there must be something in your code that makes request urls different every time.

A brief glance at your code makes this line suspicious:

_path = path + Home.instance.cacheString;

If value of Home.instance.cacheString is always different - this is definitely one of the sources of your troubles

...
Translate
LEGEND ,
Jun 30, 2013 Jun 30, 2013

Hey,

Although I am not sure where you got this advices and what context they were given under, short answers are:

1. Anything that Flash player instance does is performed in RAM. So, when you load anything - it sits in RAM unless you have an explicit mechanism that writes data on a disk. So, this RAM advice sounds like stating obvious.

2. Flash plugin, basically, can handle variations of only two protocols - http and rtmp.

3. RSL is a very extensive topic (I remember we discussed it in the past). The mere fact that you load something does not mean you utilize RSL approach. What you load is definitely library but not necessarily shared library.

You definitely need a special design and subsequent specific compilation routine (deployment strategy) in order to implement RSLs.

Looks like the main struggle here is optimization. Not only code optimization but also devising application architecture that builds a solid foundation for all-in-all performance. Beyond that - it is practically impossible to deduce what is going on in your programs without knowing much more details.

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
Participant ,
Jul 03, 2013 Jul 03, 2013

Hi Andrei, nice to see you around here.

Well, somebody helping me says that normally we make a http request with urlLoader to the server and that is what was happening each time. We weren't getting the cached swf. (that bit I don't understand and doesn't sound right - anyway...)

So he says if we create a dictionary class to hold that swf then the next time we make a request we will get the movie from there and not from the server.

I have highlighted the main parts of code below.

What I don't understand about all this is that I have never seen anything like this in my life. I have read extensively and read all about loading external files and using this type of asset manager with the dictionary class does not ring a bell and goole comes up with nothing.

I hunch is that as you say, we are doing something wrong somewhere because the only way to get an external file is via urlLoader to the server the first time and then the second time it should look for it cached on our computer is that right? Or when we make the urlLoader request how does it know to look on our computer first before going to the server or are these innner workings of the flash player I know nothing about. This is so important as when I get 10 kids on the computers they wait for as long as 5 minutes for movies that have already been downloaded many times before.

Cheers in advance.

package com.Gerry.managers.assetManager

{

    import flash.display.Loader;

    public class AssetLoader extends Loader

    {

        private var _assetName:String;

        public function AssetLoader()

        {

            super();

        }

        public function get assetName():String

        {

            return _assetName;

        }

        public function set assetName(value:String):void

        {

            _assetName = value;

        }

    }

}

--------------------------------------------------------------------------------------------------

The asset manager loading class

package com.Gerry.managers.assetManager

{

    import flash.display.Loader;

    import flash.display.LoaderInfo;

    import flash.display.MovieClip;

    import flash.display.Sprite;

    import flash.events.Event;

    import flash.net.URLRequest;

    import flash.utils.Dictionary;

    public class AssetManager extends Sprite

    {

        public static const ASSET_LOADED:String = "assetLoaded";

        private static var _instance:AssetManager;

        private var _assetsLoaded:Dictionary = new Dictionary();

        private var _assetsBeingLoaded:Dictionary = new Dictionary();

        public function AssetManager(pvt:SingletonEnforcer)

        {

        }

        /**

         * loads and asset and keeps a reference to the loaded content

         * @param name

         * @return null if the asset is not loaded yet

         *

         */

       public function loadAsset(name:String):MovieClip

        {

            var asset:MovieClip;

            if (_assetsLoaded[name])

            {

                asset = _assetsLoaded[name];

            }

            else if (_assetsBeingLoaded[name] == null)

            {

                var skinloader:AssetLoader = new AssetLoader();

                skinloader.assetName = name;

                skinloader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteF);

                skinloader.load(new URLRequest(name));

                _assetsBeingLoaded[name] = true;

            }

            return asset;

        }

        protected function loadCompleteF(e:Event):void

        {

            var skin:MovieClip = e.target.content as MovieClip;

            var name:String = ((e.target as LoaderInfo).loader as AssetLoader).assetName;

            _assetsLoaded[name] = skin;

            delete _assetsBeingLoaded[name];

            dispatchEvent(new Event(ASSET_LOADED));

        }

        /**

         * gets an instance of the class

         * @return

         *

         */

        public static function get instance():AssetManager

        {

            if (_instance == null)

            {

                _instance = new AssetManager(new SingletonEnforcer());

            }

            return _instance;

        }

    }

}

internal class SingletonEnforcer

{

}

-------------------------------------------------------------------------------------------------------------------------------------------

The function inside a class called Screen which is used by menus classes to load their swf menus.

protected function loadSkin(path:String = null):void

        {

            trace("skin to load: " + path);

            Home.instance.addPreloaderF();

            _path = path + Home.instance.cacheString;

            if (_usingAssetManager)

            {

                loadSkinFromAssetManager();

            }

            else

            {

                if (_skinloader.content)

                {

                    _skinloader.unloadAndStop(true);

                }

                _skinloader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteF);

                _skinloader.load(new URLRequest(_path));

            }

        }

        protected function loadSkinFromAssetManager(e:Event = null):void

        {

            _skin = AssetManager.instance.loadAsset(_path);

            //if no skin we have to wait to be loaded it

            if (_skin == null)

            {

                AssetManager.instance.addEventListener(AssetManager.ASSET_LOADED, loadSkinFromAssetManager);

            }

            else

            {

                AssetManager.instance.removeEventListener(AssetManager.ASSET_LOADED, loadSkinFromAssetManager);

                loadCompleteF(null);

            }

        }

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
LEGEND ,
Jul 04, 2013 Jul 04, 2013

Hey,

I don't have time now to look into it in any detail but it feels like requests are cache busted. This means that they are loaded every time - not used from cache.

Unless server is configured to non-cache, there must be something in your code that makes request urls different every time.

A brief glance at your code makes this line suspicious:

_path = path + Home.instance.cacheString;

If value of Home.instance.cacheString is always different - this is definitely one of the sources of your troubles.

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
Participant ,
Jul 04, 2013 Jul 04, 2013
LATEST

Cheers Andrei.

No time to check code but your eagle eye spied the "bug".

Cheers mate.

I'll report on my findings.

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