1 Reply Latest reply on Oct 23, 2006 8:01 AM by dimival

    Event.target doesnt work. Cant control effects.

    leotemp Level 1
      For reasons i dont understand the component im targetting with my effect function fades in and never turns invisible. Problem one is that it fades in, i cant make it fade out as alphaFrom and alphaTo are rejected as valid properties(??) problem two is that the visible function still doesnt seem to be triggered by the "effectEnd" event. Below is my application maybe somebody can point out the error (I have purposely commented out the alphaFrom and alphaTo lines but im not sure how i can control the effect if i cant specify these properties. Im also very interested in getting the event.target working in the second function as this seems to be a very important property to access in flex and a lot of my apps are sitting half done without it. Any help will get you 10 Unicorn points and 1 Gold Spider Man point (collect them all!).

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

      <mx:Canvas x="417" y="249" width="96" height="96" id="canvasTest" borderStyle="solid" backgroundColor="#ffffff" click="{componentVanish(canvasTest,2000)}">
      </mx:Canvas>

      <mx:Script>
      <![CDATA[
      // IMPORT NEEDED PACKAGES //
      import mx.effects.*;

      public function componentVanish(obj:Object,dur:Number):void
      {
      //ISTANTIATE FADE COMPONENT//
      var hideFade:Effect = new mx.effects.Fade();
      //CREATE EVENT LISTENER FOR NEW EFFECTS "effectEnd" EVENT//
      hideFade.addEventListener("effectEnd", componentHide);
      //SET METHODS FOR NEW FADE EFFECT//
      //hideFade.alphaFrom = 1.0; //UNIDENTIFIED PROPERTY!//
      //hideFade.alphaTo = 0.0; //UNIDENTIFIED PROPERTY!//
      hideFade.target = obj;
      hideFade.duration = dur;
      //EXECUTE EFFECT//
      hideFade.play();
      }
      public function componentHide(event:flash.events.Event):void
      {
      event.target.visible = false; //DOES NOT APPEAR TO BE EXECUTED//
      }

      ]]>
      </mx:Script>

      </mx:Application>
        • 1. Re: Event.target doesnt work. Cant control effects.
          dimival Level 1
          First of all, which component are you trying to fade out? the canvas? If it is the canvas then you need to do one of these:
          a) Add an event listener to the Canvas so it can listen to the effectEnd and then make it fade in or out
          <mx:Canvas x="417" y="249" width="96" height="96" id="canvasTest" borderStyle="solid" backgroundColor="#ffffff" click="componentVanish(canvasTest,2000)" effectEnd="canvasTest.visible = false">
          </mx:Canvas>
          b) In your componentHide function change the canva's visible property
          public function componentHide(event:flash.events.Event):void
          {
          canvasTest.visible = false;
          }

          Both of these should work, so choose the one you like more. Now let me explain about the events. When you dispatch an event, that event has data regarding who dispatched it and who's listening to it. The target property is the object who dispatched the event, so in your code you are trying to change the visible property of your effect object, which obviously is doing nothing because the effect is not a visual component. There is also a currentTarget which is the object that is listening the event at the time, so if you add a listener to your canvas and bythe time your listener function is executed the currentTarget property will be a reference to your canvas which is the object listening to the event at that moment.
          I recommend you to check out the Developer's Guide event chapter, it contains a more detailed explanation on this.