2 Replies Latest reply on Jun 29, 2011 7:52 PM by yancaoshi

    Set effect to BitmapImage with actionscript


      Hi all,


      I met this in a mobile application which needs to display icon in IconItemRenderer with a Fade effect(Alpha from 0 to 1.0). But to me, it's general that how to set effect with actionscript? More, I am not sure whether the BitmapImage support this.


      Would anybody help to show me the codes of setting effect(not MXML)?




        • 1. Re: Set effect to BitmapImage with actionscript
          saisri2k2 Level 4

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                            xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
                         import mx.events.EffectEvent;
                         import mx.events.FlexEvent;
                         import spark.effects.Fade;
                         protected function application1_creationCompleteHandler(event:FlexEvent):void
                              var fade:Fade = getFade();
                              fade.target = xx;
                         private function getFade():Fade{
                              var f:Fade = new Fade();
                              f.alphaFrom = 1;
                              f.alphaTo = 0.2;
                              return f;
                    <s:BitmapImage source="@Embed('appicon_48x48.png')" width="100" height="100" id="xx"/>


          This some how worked for me.

          • 2. Re: Set effect to BitmapImage with actionscript
            yancaoshi Level 1

            Thank you so much though it was not exact what I need.


            Let me explain the answer a little more. I am working with a mobile project which makes use of IconItemRenderer and the icon is BitmapImage. Because that primitive class doesn't support Effect, I was not able to use setStyle method.


            You answer helps me out. Now, I listen to the event COMPLETE of iconDisplay and play the effect in the event handler.


            Thanks again