A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: Cannot addChild on stage after EventDispatcher successfully loaded the image???

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180

    Cannot addChild on stage after EventDispatcher successfully loaded the image???

    I am trying to learn how to use EventDispatcher. I create xml gallery where I am loading content via xml. In this particular case, I am not loading a sequence of multiple images. I load just one image. I traced the path to the image location and it is correct. I have a very hard time placing the loaded item to stage. I can trace EventDispatcher functions from EventDispather Class. When I do that, the trace statements confirm that the image is loaded. I am wondering what I should do in order to place the image on stage. I definitely cannot do it from EventDispatcher class directly or I am missing something. Below is my EventDispatcher class.
    Please help me to find out about the correct technique to add the loaded item on stage after EventDispatcher was run. Below is the class of my EventDispatcher.

    Any advice is highly appreciated. Any good tutorial link is also a great help for me. Thank you in advance.


    Actionscript Code:
    package net.EvtDisp {

        import flash.display.Bitmap;
        import flash.display.BitmapData;
        import flash.display.Loader;
        import flash.display.PixelSnapping;
        import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.events.IOErrorEvent;
        import flash.events.ProgressEvent;
        import flash.net.URLRequest;
           
        public class UIItems extends EventDispatcher {
           
            // The name of the event to be fired when loading the im is finished
            public static const TYPESH_LOADED:String = "typeShLoaded"
           
            // The loader to be used for loading the original im
            private var _typeShLoader:Loader = new Loader();
           
            // The original im as a Bitmap
            private var _typeShowIm:Bitmap;
           
            private var _typeS:String;
           
            // A URLRequest instance to be used while loading the images
            private var urlRequest:URLRequest;
           
            public function UIItems(_typeSh:String) {
                trace ("UIItems.as UIItems ()  Run");
                this._typeS = _typeSho;
                trace ("this._typeS = " +(ConfigManager.TYPESh_DIR+this._typeS));
                //loadtypeSh();  //By running loadtypeSh() I can trace if the image was successfully loaded
           
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////////
           
            public function loadtypeSh():void {                
                trace ("UI Item  loadtypeSh() Run");
                // Start loading the typeSh
                _typeShLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onTypeShProgress);
                _typeShLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onTypeShComplete);
                _typeShLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
               
                // Start loading the typeSh
                _typeShLoader.load(new URLRequest(ConfigManager.TYPESh_DIR + _typeS));
                //trace (ConfigManager.TYPESH_DIR + _typeS);
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////////
           
            //This method is called when loading the typeSh is completed.
            private function onTypeShComplete(evt:Event):void {
                trace ("Run dispatchEvent");
                // Copy the content of the loader as bitmap
                var bitmapData:BitmapData = new BitmapData(_typeShLoader.width, _typeShLoader.height, true, 0x00000000);
                bitmapData.draw(_typeShLoader);
                _typeShowIm = new Bitmap(bitmapData, PixelSnapping.NEVER, true);
                //addChild(_typeShowIm);
                // Fire the event
                dispatchEvent(new Event(TYPESH_LOADED));
                trace (TYPESh_LOADED);
               
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////////
           
            //This method is called during the Type Sh Image loading process.
            private function onTypeShProgress(evt:ProgressEvent):void {
                trace ("Run onTypeShProgress");
                dispatchEvent(evt);
               
            }
           
            /////////////////////////////////////////////////////////////////////////////////////////////////////
           
            //This method is called if an error occurs during the loading process.
           
            private function onIOError(evt:IOErrorEvent):void {
                trace ("Run onIOError");
                dispatchEvent(evt);
               
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////////
           
            //Returns the original typeSh.
           
            /*public function get _typeSh():String {
                trace ("_typeSh Did");
                return _typeS;
               
            }*/

           
            public function get typeShIm():Bitmap {
                trace ("_typeSh Did");
                return _typeShowIm;
               
            }
           
        }  
       
    }
    Last edited by vladc77; 05-21-2010 at 12:34 PM.
    Best regards
    Vlad,

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center