Flex 中利用Matrix 类的rotate函数对图片进行旋转操作的例子

下面是完整代码(或点击这里察看):

Download:  main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="horizontal"
  4.         verticalAlign="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:String id="deg">&#0176;</mx:String>
  8.  
  9.     <mx:Script>
  10.         <![CDATA[
  11.             import mx.core.UIComponent;
  12.  
  13.             private function img1_effectEnd():void {
  14.                 /* Set the appropriate Label text. */
  15.                 lbl1.text = "img1.rotation = " + img1.rotation.toString() + deg;
  16.             }
  17.  
  18.             private function img2_creationComplete():void {
  19.                 /* "Copy" the existing matrix. */
  20.                 var m1:Matrix = img2.transform.matrix;
  21.                 /* Rotate the matrix 45 degrees (note that we have to
  22.                    convert from degrees to radians since the rotate()
  23.                    method expects radians. */
  24.                 m1.rotate(degreesToRadians(45));
  25.                 /* Concatenate the original matrix onto the rotated
  26.                    matrix so we don't lose the original X and Y
  27.                    coordinates and any other effects. */
  28.                 m1.concat(img2.transform.matrix);
  29.                 /* "Copy" the new matrix over the existing matrix. */
  30.                 img2.transform.matrix = m1;
  31.                 /* Set the appropriate Label text. */
  32.                 lbl2.text = "img2.rotation = " + img2.rotation.toString() + deg;
  33.             }
  34.  
  35.             private function img_rollOver(cTarget:UIComponent):void {
  36.                 cTarget.toolTip = cTarget.name + ".rotation = " + cTarget.rotation.toString();
  37.             }
  38.  
  39.             private function radiansToDegrees(radians:Number):Number {
  40.                 var degrees:Number = radians * (180 / Math.PI);
  41.                 return degrees;
  42.             }
  43.  
  44.             private function degreesToRadians(degrees:Number):Number {
  45.                 var radians:Number = degrees * (Math.PI / 180);
  46.                 return radians;
  47.             }
  48.         ]]>
  49.     </mx:Script>
  50.  
  51.     <mx:Rotate id="rotate" angleFrom="0" angleTo="45" duration="1" />
  52.  
  53.     <mx:ApplicationControlBar dock="true">
  54.         <mx:Label id="lbl1" />
  55.         <mx:Spacer width="50" />
  56.         <mx:Label id="lbl2" />
  57.     </mx:ApplicationControlBar>
  58.  
  59.     <mx:Image id="img1"
  60.             source="http://www.helpexamples.com/flash/images/logo.png"
  61.             creationCompleteEffect="{rotate}"
  62.             effectEnd="img1_effectEnd();"
  63.             rollOver="img_rollOver(UIComponent(event.currentTarget));" />
  64.  
  65.     <mx:Spacer width="50" />
  66.  
  67.     <mx:Image id="img2"
  68.             source="http://www.helpexamples.com/flash/images/logo.png"
  69.             creationComplete="img2_creationComplete();"
  70.             rollOver="img_rollOver(UIComponent(event.currentTarget));" />
  71.  
  72. </mx:Application>

 

 

原文:http://blog.minidx.com/2008/09/21/1409.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值