10
Dec
07

Rotating images using the Rotate class

The following example shows how you can rotate an image around an arbitrary X and Y origin using the <mx:Rotate /> tag in Flex.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/12/10/rotating-images-using-the-rotate-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Rotate id="rotate"
            target="{img}"
            angleFrom="0"
            angleTo="360"
            duration="1000"
            originX="{imgOriginX.value}"
            originY="{imgOriginY.value}" />

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="originX:">
                <mx:NumericStepper id="imgOriginX"
                        minimum="0"
                        maximum="{img.width}"
                        value="0" />
            </mx:FormItem>
            <mx:FormItem label="originY:">
                <mx:NumericStepper id="imgOriginY"
                        minimum="0"
                        maximum="{img.height}"
                        value="0" />
            </mx:FormItem>
            <mx:FormItem>
                <mx:Button label="Rotate"
                        click="rotate.play();" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:Image id="img" source="@Embed('flex_logo.jpg')" />

</mx:Application>

View source is enabled in the following example.


2 Responses to “Rotating images using the Rotate class”


  1. 1 lala Oct 2nd, 2008 at 5:37 pm

    i wante to do that when i rollOver why can i do that ??? please

  2. 2 peterd Oct 2nd, 2008 at 6:50 pm

    lala,

    You can try setting the rollOverEffect style/effect:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
            layout="vertical"
            verticalAlign="middle"
            backgroundColor="white">
    
        <mx:Rotate id="rotate"
                target="{img}"
                angleFrom="0"
                angleTo="360"
                duration="1000"
                originX="{img.height/2}"
                originY="{img.width/2}" />
    
        <mx:Image id="img"
                source="fx_appicon-tn.gif"
                rollOverEffect="{rotate}" />
    
    </mx:Application>
    

    Peter

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




December 2007
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed