0 Replies Latest reply on Nov 11, 2009 2:59 AM by Stuart McD

    addedEffect doesnt work by creationCompleteEffect does?

    Stuart McD

      Hi,

      I've just started looking at Flex after decades(!) of C/C++ and my first simple test program is working, but I'm not sure why

      I am adding some Text to a Canvas with an addText function called via setTimeout(addText,1000).If I manual create the Text and use  setStyle("addedEffect",dissolveIn) it works. If made a DissolveText.mxml and set addedEffect="{dissolveIn}" it doesn't. I also tried using setStyle and that didn't work. I found I had to use creationCompleteEffect="{dissolveIn}".

       

      NOTE: The setTimeout was because originally I wasn't sure if there were problems caused by trying to do things in a creationComplete function.

       

      Can someone explain what's going on here?

       

         Thanks,


      Stuart.


      Main.mxml

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

          <mx:Script>
          <![CDATA[ 
              import mx.controls.Text;
              import mx.effects.Dissolve;
              import components.DissolveText;
             
              private function creationComplete():void
              {
                  setTimeout(addText,1000);
              }
              private function addText():void
              {
                  // Creating a Text object and setting addedEffect works
                  var t1:Text = new Text();
                  var addedEff:Dissolve = new Dissolve();
                  addedEff.alphaFrom = 0;
                  addedEff.alphaTo = 1;
                  addedEff.duration = 1000;
                  t1.setStyle("addedEffect", addedEff);
                  t1.text = "HELLO";
                  theCanvas.addChild(t1);
                 
                  // Creating a DissolveText only works with creationCompleteEffect
                  var t2:DissolveText = new DissolveText();
                  t2.text = "WORLD";
                  t2.y = 100;
                  theCanvas.addChild(t2);
              }
          ]]>       
          </mx:Script>

             
          <mx:Canvas id="theCanvas"
              fontSize="40"
              width = "500"
              height = "500">
          </mx:Canvas>
         
      </mx:Application>

      DissolveText.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <!-- This works -->
      <mx:Text xmlns:mx="http://www.adobe.com/2006/mxml"    creationCompleteEffect="{dissolveIn}" >

      <!-- AdddedEffect does not work
      <mx:Text xmlns:mx="http://www.adobe.com/2006/mxml"    addedEffect="{dissolveIn}" >
      -->

      <!-- Creating the effect manually doesn't work
      <mx:Text xmlns:mx="http://www.adobe.com/2006/mxml"    creationComplete="creationComplete()" >
             
          <mx:Script>
          <![CDATA[ 
              import mx.effects.Dissolve;
             
              private function creationComplete():void
              {
                  var addedEff:Dissolve = new Dissolve();
                  addedEff.alphaFrom = 0;
                  addedEff.alphaTo = 1;
                  addedEff.duration = 1000;
                  setStyle("addedEffect", addedEff);
              }
              ]]>
          </mx:Script>
      -->
         
          <mx:Dissolve id = "dissolveIn" duration="1000" alphaFrom="0.0" alphaTo="1.0" />
      </mx:Text>