<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Setting a complete effect on an Image control in Flex</title>
	<atom:link href="http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Mon, 22 Mar 2010 01:36:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Javier Julio</title>
		<link>http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/comment-page-1/#comment-3424</link>
		<dc:creator>Javier Julio</dc:creator>
		<pubDate>Tue, 19 May 2009 23:09:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/#comment-3424</guid>
		<description>@cool

I&#039;ve wanted to implement the same thing and I&#039;ve done this by adding a custom effect to a class extending Image called sourceChangingEffect. The component shouldn&#039;t be named Photo but in this case I was using it to display Photo objects. Feel to try it out. I&#039;m not sure if I have it completely spot on but some testing shows it works well.

&lt;pre class=&quot;code&quot;&gt;
package com.arc90.fresh.controls
{
    import flash.events.Event;

    import mx.controls.Image;
    import mx.core.mx_internal;
    import mx.effects.EffectManager;
    import mx.events.EffectEvent;
    import mx.styles.StyleManager;

    use namespace mx_internal;

    //--------------------------------------
    //  Effects
    //--------------------------------------

    /**
     * Played when the source is changed but before it is replaced with
     * the new provided source.
     */
    [Effect(name=&quot;sourceChangingEffect&quot;, event=&quot;sourceChanging&quot;)]

    /**
     *
     */
    public class Photo extends Image
    {
        //-----------------------------------------------------------------
        //
        //  Class variables
        //
        //-----------------------------------------------------------------

        /**
         * @private
         * Trigger when static instance is created to set defaults.
         */
        private static var classConstructed:Boolean = constructClass();

        //-----------------------------------------------------------------
        //
        //  Class methods
        //
        //-----------------------------------------------------------------

        /**
         * @private
         * Triggered to run when static instance is created so defaults
         * are set.
         */
        private static function constructClass():Boolean
        {
            EffectManager.registerEffectTrigger(&quot;sourceChangingEffect&quot;, &quot;sourceChanging&quot;);

            return true;
        }

        //-----------------------------------------------------------------
        //
        //  Variables
        //
        //-----------------------------------------------------------------

        /**
         * Storage for the boolean indicating that a sourceChangingEffect the new
         * the new been specified.
         */
        protected var hasSourceChangingEffect:Boolean = false;

        /**
         * Storage for the new source property value. When a
         * sourceChangingEffect style is defined we need to temporarily
         * store the new source before actually committing it. Once the
         * effect is done then we commit the new source value.
         */
        protected var newSource:Object;

        //-----------------------------------------------------------------
        //
        //  Constructor
        //
        //-----------------------------------------------------------------

        /**
         * Constructor.
         */
        public function Photo()
        {
            super();
        }

        //-----------------------------------------------------------------
        //
        //  Overridden properties
        //
        //-----------------------------------------------------------------

        //----------------------------------
        //  source
        //----------------------------------

        /**
         * @private
         */
        private var sourceChanged:Boolean = false;

        /**
         * @private
         */
        override public function set source(value:Object):void
        {
            if (value == source)
                return;

            // if we made it this far then we have changed the source, if
            // we&#039;vebeen given a sourceChangingEffect style then we need
            // to wait before committing the new source value
            if (StyleManager.isValidStyleValue(getStyle(&quot;sourceChangingEffect&quot;)))
            {
                if (isEffectStarted)
                {
                    removeEventListener(EffectEvent.EFFECT_END, effectEndHandler);
                    endEffectsStarted();
                }

                // if source wasn&#039;t defined then we are setting it for the
                // first time
                if (!source)
                    super.source = value;
                else
                {
                    hasSourceChangingEffect = true;

                    addEventListener(EffectEvent.EFFECT_END, effectEndHandler);

                    dispatchEvent(new Event(&quot;sourceChanging&quot;));
                }
            }
            else // otherwise we work as we would normally, just commit new value
            {
                hasSourceChangingEffect = false;
                removeEventListener(EffectEvent.EFFECT_END, effectEndHandler);

                super.source = value;
            }

            newSource = value;
        }

        //-----------------------------------------------------------------
        //
        //  Event handler
        //
        //-----------------------------------------------------------------

        /**
         * @private
         */
        private function effectEndHandler(event:EffectEvent):void
        {
            removeEventListener(EffectEvent.EFFECT_END, effectEndHandler);

            if (hasSourceChangingEffect)
            {
                // now that our effect has finished commit the new source,
                // the parent (SWFLoader) takes care of everything we need
                super.source = newSource;
            }
        }
    }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@cool</p>
<p>I&#8217;ve wanted to implement the same thing and I&#8217;ve done this by adding a custom effect to a class extending Image called sourceChangingEffect. The component shouldn&#8217;t be named Photo but in this case I was using it to display Photo objects. Feel to try it out. I&#8217;m not sure if I have it completely spot on but some testing shows it works well.</p>
<pre class="code">
package com.arc90.fresh.controls
{
    import flash.events.Event;

    import mx.controls.Image;
    import mx.core.mx_internal;
    import mx.effects.EffectManager;
    import mx.events.EffectEvent;
    import mx.styles.StyleManager;

    use namespace mx_internal;

    //--------------------------------------
    //  Effects
    //--------------------------------------

    /**
     * Played when the source is changed but before it is replaced with
     * the new provided source.
     */
    [Effect(name="sourceChangingEffect", event="sourceChanging")]

    /**
     *
     */
    public class Photo extends Image
    {
        //-----------------------------------------------------------------
        //
        //  Class variables
        //
        //-----------------------------------------------------------------

        /**
         * @private
         * Trigger when static instance is created to set defaults.
         */
        private static var classConstructed:Boolean = constructClass();

        //-----------------------------------------------------------------
        //
        //  Class methods
        //
        //-----------------------------------------------------------------

        /**
         * @private
         * Triggered to run when static instance is created so defaults
         * are set.
         */
        private static function constructClass():Boolean
        {
            EffectManager.registerEffectTrigger("sourceChangingEffect", "sourceChanging");

            return true;
        }

        //-----------------------------------------------------------------
        //
        //  Variables
        //
        //-----------------------------------------------------------------

        /**
         * Storage for the boolean indicating that a sourceChangingEffect the new
         * the new been specified.
         */
        protected var hasSourceChangingEffect:Boolean = false;

        /**
         * Storage for the new source property value. When a
         * sourceChangingEffect style is defined we need to temporarily
         * store the new source before actually committing it. Once the
         * effect is done then we commit the new source value.
         */
        protected var newSource:Object;

        //-----------------------------------------------------------------
        //
        //  Constructor
        //
        //-----------------------------------------------------------------

        /**
         * Constructor.
         */
        public function Photo()
        {
            super();
        }

        //-----------------------------------------------------------------
        //
        //  Overridden properties
        //
        //-----------------------------------------------------------------

        //----------------------------------
        //  source
        //----------------------------------

        /**
         * @private
         */
        private var sourceChanged:Boolean = false;

        /**
         * @private
         */
        override public function set source(value:Object):void
        {
            if (value == source)
                return;

            // if we made it this far then we have changed the source, if
            // we'vebeen given a sourceChangingEffect style then we need
            // to wait before committing the new source value
            if (StyleManager.isValidStyleValue(getStyle("sourceChangingEffect")))
            {
                if (isEffectStarted)
                {
                    removeEventListener(EffectEvent.EFFECT_END, effectEndHandler);
                    endEffectsStarted();
                }

                // if source wasn't defined then we are setting it for the
                // first time
                if (!source)
                    super.source = value;
                else
                {
                    hasSourceChangingEffect = true;

                    addEventListener(EffectEvent.EFFECT_END, effectEndHandler);

                    dispatchEvent(new Event("sourceChanging"));
                }
            }
            else // otherwise we work as we would normally, just commit new value
            {
                hasSourceChangingEffect = false;
                removeEventListener(EffectEvent.EFFECT_END, effectEndHandler);

                super.source = value;
            }

            newSource = value;
        }

        //-----------------------------------------------------------------
        //
        //  Event handler
        //
        //-----------------------------------------------------------------

        /**
         * @private
         */
        private function effectEndHandler(event:EffectEvent):void
        {
            removeEventListener(EffectEvent.EFFECT_END, effectEndHandler);

            if (hasSourceChangingEffect)
            {
                // now that our effect has finished commit the new source,
                // the parent (SWFLoader) takes care of everything we need
                super.source = newSource;
            }
        }
    }
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: flexlingie</title>
		<link>http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/comment-page-1/#comment-3425</link>
		<dc:creator>flexlingie</dc:creator>
		<pubDate>Wed, 11 Feb 2009 02:45:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/#comment-3425</guid>
		<description>This is a really nice, simple example - thanks!</description>
		<content:encoded><![CDATA[<p>This is a really nice, simple example &#8211; thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carlos</title>
		<link>http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/comment-page-1/#comment-3423</link>
		<dc:creator>Carlos</dc:creator>
		<pubDate>Tue, 15 Jul 2008 23:20:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/#comment-3423</guid>
		<description>Nice post!</description>
		<content:encoded><![CDATA[<p>Nice post!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cool</title>
		<link>http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/comment-page-1/#comment-3422</link>
		<dc:creator>cool</dc:creator>
		<pubDate>Wed, 09 Jul 2008 14:58:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.flexexamples.com/2008/06/29/setting-a-complete-effect-on-an-image-control-in-flex/#comment-3422</guid>
		<description>nice, is there a way to add fadeOut for hideEffect ?

where can I find the value for effects? such as you used in your script &quot;Face&quot;</description>
		<content:encoded><![CDATA[<p>nice, is there a way to add fadeOut for hideEffect ?</p>
<p>where can I find the value for effects? such as you used in your script &#8220;Face&#8221;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
