Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 996553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:53:36+00:00 2026-05-16T06:53:36+00:00

I have a Main class loading 2 SWF (loader and viewer, also with document

  • 0

I have a Main class loading 2 SWF (loader and viewer, also with document classes). They need to share a double buffer with content, of course, filled by loader and showed by viewer

I was thinking to use the LocalConnection class but after a suggestion from PatrickS now I’m evaluating the possibility of a Singleton Class. I’ve never used this pattern in AS and must confess I’m rather biased against it. But in this particular case I guess it’ll be useful. By the way, a little bit surprised reading in the gskinner blog 2 implementations examples. So, I’ll really appreciate your views, knowing this subject is an endless war like the Mac vs PC one

Take into account:
1. AIR desktop application running 24×7 during some months in a high-end Windows PC. No user interaction
2. High performance code is a must because content loaded are full HD images

My other concern is about memory leaks

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:53:37+00:00Added an answer on May 16, 2026 at 6:53 am

    I’d avoid a Singleton, personally, as its regularly implemented. However, having a single instance of this buffer object makes sense. So what I’d do in this case is have your Main class created this object. When the viewer is loaded, pass it this object. Then do the same for the loader. Now, both of your swfs share a common object that they could use to communicate. Then you can call functions on it and make it dispatch events if you want (extending EventDispatcher or implementing IEventDispatcher). Or you can just register callbacks if you want (should be a bit faster, but not sure if it will make a big difference).

    Edit

    Having a look at your other question I think your problem was related to getting the right loader and passing data to the loaded content. Here’s an skecth of how you could implement what I mentioned above.

    PhotoLoader.swf:

    package  {
    import flash.display.Sprite;
    import flash.events.Event;
    
    public class PhotoLoader extends Sprite {
    
        private var _commonObject:CommonObject;
    
        public function PhotoLoader() {
    
        }
    
        public function setCommonObject(commonObject:CommonObject):void {
            trace("PhotoLoader::setCommonObject", commonObject);
            _commonObject = commonObject;
            _commonObject.addEventListener(Event.INIT,handleInit);
        }
    
        private function handleInit(e:Event):void {
            trace("PhotoLoader::handleInit");
        }
    
    }
    
    } 
    

    PhotoViewer.swf:

    package  {
        import flash.display.Sprite;
        import flash.events.Event;
    
        public class PhotoViewer extends Sprite {
    
            private var _commonObject:CommonObject;
    
            public function PhotoViewer() {
    
            }
    
            public function setCommonObject(commonObject:CommonObject):void {
                trace("PhotoLoader::setCommonObject", commonObject);
                _commonObject = commonObject;
                _commonObject.addEventListener(Event.INIT,handleInit);
            }
    
            private function handleInit(e:Event):void {
                trace("PhotoViewer::handleInit");
            }
    
        }
    
    }
    

    Main.swf

    package {
        import flash.display.Loader;
        import flash.display.LoaderInfo;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.net.URLRequest;
        import flash.system.ApplicationDomain;
        import flash.system.LoaderContext;
    
        public class Main extends Sprite {
    
            private var _photoLoader:PhotoLoader;
            private var _photoViewer:PhotoViewer;
            private var _commonObject:CommonObject;
    
            private var _viewerLoader:Loader;
            private var _loaderLoader:Loader;
    
            private var _count:int = 0;
    
            public function Main():void {
                _commonObject = new CommonObject();
                loadSwfs();
    
            }
    
            private function loadSwfs():void {
    
                _viewerLoader = new Loader();
                _viewerLoader.contentLoaderInfo.addEventListener(Event.INIT,handleInit);
                _viewerLoader.load(new URLRequest("PhotoViewer.swf"));
    
                _loaderLoader = new Loader();
                _loaderLoader.contentLoaderInfo.addEventListener(Event.INIT,handleInit);
                _loaderLoader.load(new URLRequest("PhotoLoader.swf"));
    
            }
    
            private function handleInit(e:Event):void {
                trace("handleInit");
                var loader:Loader = (e.target as LoaderInfo).loader;
                switch(loader) {
                    case _viewerLoader:
                        _photoViewer = _viewerLoader.content as PhotoViewer; 
                        _photoViewer.setCommonObject(_commonObject);
                        _count++;
                        break;
                    case _loaderLoader:
                        _photoLoader = _loaderLoader.content as PhotoLoader; 
                        _photoLoader.setCommonObject(_commonObject);
                        _count++;
                        break;
                }
                if(_count == 2) { 
                    _commonObject.init();
                }
    
            }
    
    
        }
    
    }
    

    And the common object, shared by the 3 swf:

    package  {
        import flash.events.Event;
        import flash.events.EventDispatcher;
    
        public class CommonObject extends EventDispatcher {
    
            public function CommonObject() {
    
            }
    
            public function init():void {
                dispatchEvent(new Event(Event.INIT));
            }
        }
    
    }
    

    Basically when you load both your viewer and loader swfs you pass an instance of this common object. Then you register to listen for an INIT method: this will tell loader and viewer that everything has been setup. So at this point you can start sending messages from your viewer or loader to the other party (you could implement this through event dispatching); basically make a method in the common object to do it for you or just call dispatchEvent on the common object directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main class and two extended classes: class Main { public $foo;
I am loading an external class using a class-loader. I have a custom security
I have a swf file sample.swf which has its actionscript class in Main.as. This
I have defined an ArrayList in my main class where I am loading data
I have my main class PayUnit where I create my main object references, such
I have one main class with several inherited members who all overload the same
I have a main class in a program that launches another class that handles
I have a main class(which is basically a netbeans form;drag and drop) from where
I have a Main class and a HelloWorld class. I have created a button
So I have a main class and another class that has a variable I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.