1 Reply Latest reply on Apr 11, 2007 8:21 AM by 187_2007

    PLEASE HELP. Tirggering "complete" event of progressBar

    leotemp Level 1
      I have a progress bar that has an image control as its "source" and its complete event is never fired after the image has finished loading. Ive tried Event.COMPLETE, "Event.COMPLETE", "complete" and all kinds of other things in my even listener and it never works, whats annoying is that if i put the complete="loadComplete()" in my progressBar tag it does work. Whats going on?

      Below is my code. There is allot of stuff going on that is dependent on data from an HTTPService, I know that works fine though as I can see the progress bar load the data and the image rolls to the new source when it completes, just no event listener is triggered.

      CODE:

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="{getMedia('home')}" viewSourceURL="srcview/index.html" width="100%" height="100%" backgroundGradientColors="[#808080, #000000]" layout="absolute">

      <mx:HTTPService id="xmlMediaList" url="xml.test.xml" method="GET"/>

      <mx:Script>
      <![CDATA[

      import mx.rpc.events.*
      import flash.events.*

      // PAGE INITIALIZE FUNCTIONIONALITY //
      // sends request for images to server //
      private var loadTrack:Number=0; //Tracks how many assets have been loaded//
      private var loadCount:Number; //Tracks total number of assets to load//
      private var arrayImages:Array; //Stores assets to load //
      private function getMedia(page:String):void {
      var params:Object= new Object;
      params.func= "loadImages";
      params.page= "home";
      // create listener for server returned result //
      xmlMediaList.addEventListener("result" , buildMediaArray);
      // send request to server //
      xmlMediaList.send(params);
      }
      private function buildMediaArray(event:ResultEvent):void {
      arrayImages= mx.utils.ArrayUtil.toArray(event.result.xml.image);
      loadCount=arrayImages[0].length;
      loadMedia();
      }

      private function loadMedia():void {
      if (loadTrack!=loadCount) {
      var obj:Object= this[arrayImages[0][loadTrack].id.toString()];
      var src:String= "img/flex/"+ arrayImages[0][loadTrack].name.toString();

      // THIS IS THE LINE HERE THAT DOESNT SEEM TO WORK!//
      progBar.addEventListener("complete", loadComplete);

      progBar.source= obj;
      progBar.visible= true;
      obj.load(src);
      debug.text= "loading file, please wait..."
      }
      }

      private function loadComplete():void {
      debug.text= "file loaded";
      progBar.visible= false;
      }
      ]]>
      </mx:script>


      <mx:Image scaleContent="true" maintainAspectRatio="false" id="imgBGGround" x="0" width="750" height="550" bottom="0"/>

      <mx:Label x="10" y="10" text="Label" id="debug" color="#ffffff"/>

      <mx:ProgressBar x="249" y="198" id="progBar" fontFamily="Arial" color="#ffffff" visible="false"/>


      </mx:Application>