Flex中如何利用Matrix类的rotate函数对图片进行旋转操作的例子
2010-04-23 09:54
686 查看
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
verticalAlign="middle"
backgroundColor="white">
<mx:String id="deg">°</mx:String>
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private function img1_effectEnd():void {
/* Set the appropriate Label text. */
lbl1.text = "img1.rotation = " + img1.rotation.toString() + deg;
}
private function img2_creationComplete():void {
/* "Copy" the existing matrix. */
var m1:Matrix = img2.transform.matrix;
/* Rotate the matrix 45 degrees (note that we have to
convert from degrees to radians since the rotate()
method expects radians. */
m1.rotate(degreesToRadians(45));
/* Concatenate the original matrix onto the rotated
matrix so we don't lose the original X and Y
coordinates and any other effects. */
m1.concat(img2.transform.matrix);
/* "Copy" the new matrix over the existing matrix. */
img2.transform.matrix = m1;
/* Set the appropriate Label text. */
lbl2.text = "img2.rotation = " + img2.rotation.toString() + deg;
}
private function img_rollOver(cTarget:UIComponent):void {
cTarget.toolTip = cTarget.name + ".rotation = " + cTarget.rotation.toString();
}
private function radiansToDegrees(radians:Number):Number {
var degrees:Number = radians * (180 / Math.PI);
return degrees;
}
private function degreesToRadians(degrees:Number):Number {
var radians:Number = degrees * (Math.PI / 180);
return radians;
}
]]>
</mx:Script>
<mx:Rotate id="rotate" angleFrom="0" angleTo="45" duration="1" />
<mx:ApplicationControlBar dock="true">
<mx:Label id="lbl1" />
<mx:Spacer width="50" />
<mx:Label id="lbl2" />
</mx:ApplicationControlBar>
<mx:Image id="img1"
source="http://www.helpexamples.com/flash/images/logo.png"
creationCompleteEffect="{rotate}"
effectEnd="img1_effectEnd();"
rollOver="img_rollOver(UIComponent(event.currentTarget));" />
<mx:Spacer width="50" />
<mx:Image id="img2"
source="http://www.helpexamples.com/flash/images/logo.png"
creationComplete="img2_creationComplete();"
rollOver="img_rollOver(UIComponent(event.currentTarget));" />
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="horizontal"
verticalAlign="middle"
backgroundColor="white">
<mx:String id="deg">°</mx:String>
<mx:Script>
<![CDATA[
import mx.core.UIComponent;
private function img1_effectEnd():void {
/* Set the appropriate Label text. */
lbl1.text = "img1.rotation = " + img1.rotation.toString() + deg;
}
private function img2_creationComplete():void {
/* "Copy" the existing matrix. */
var m1:Matrix = img2.transform.matrix;
/* Rotate the matrix 45 degrees (note that we have to
convert from degrees to radians since the rotate()
method expects radians. */
m1.rotate(degreesToRadians(45));
/* Concatenate the original matrix onto the rotated
matrix so we don't lose the original X and Y
coordinates and any other effects. */
m1.concat(img2.transform.matrix);
/* "Copy" the new matrix over the existing matrix. */
img2.transform.matrix = m1;
/* Set the appropriate Label text. */
lbl2.text = "img2.rotation = " + img2.rotation.toString() + deg;
}
private function img_rollOver(cTarget:UIComponent):void {
cTarget.toolTip = cTarget.name + ".rotation = " + cTarget.rotation.toString();
}
private function radiansToDegrees(radians:Number):Number {
var degrees:Number = radians * (180 / Math.PI);
return degrees;
}
private function degreesToRadians(degrees:Number):Number {
var radians:Number = degrees * (Math.PI / 180);
return radians;
}
]]>
</mx:Script>
<mx:Rotate id="rotate" angleFrom="0" angleTo="45" duration="1" />
<mx:ApplicationControlBar dock="true">
<mx:Label id="lbl1" />
<mx:Spacer width="50" />
<mx:Label id="lbl2" />
</mx:ApplicationControlBar>
<mx:Image id="img1"
source="http://www.helpexamples.com/flash/images/logo.png"
creationCompleteEffect="{rotate}"
effectEnd="img1_effectEnd();"
rollOver="img_rollOver(UIComponent(event.currentTarget));" />
<mx:Spacer width="50" />
<mx:Image id="img2"
source="http://www.helpexamples.com/flash/images/logo.png"
creationComplete="img2_creationComplete();"
rollOver="img_rollOver(UIComponent(event.currentTarget));" />
</mx:Application>
相关文章推荐
- Flex中如何利用Matrix类的rotate函数对图片进行旋转操作的例子
- Flex 中利用Matrix 类的rotate函数对图片进行旋转操作的例子
- Flex中如何利用dataDescriptor和labelFunction属性以及hasChildren()和getChildren()函数设置Tree中包含子节点个数的例子
- Flex中如何利用useHandCursor和buttonMode属性在鼠标移到图片上显示手型光标的例子
- Linux网络编程一步一步学-利用OpenSSL提供的SSL操作函数进行加密通讯原始例子
- Flex中如何利用Bitmap和BitmapData类复制图片到一个TileList控件的例子
- Flex中如何利用setInterval()和clearInterval()函数按照一定时间有规则的执行函数的例子
- Flex中如何利用Style Sheet和<mx:style>标签嵌入图片/图标的例子
- Flex中如何利用FocusManager类的setFocus函数设置TextInput的焦点的例子
- Linux网络编程一步一步学-利用OpenSSL提供的SSL操作函数进行加密通讯原始例子
- Flex中如何利用树形控件(Tree Control)和SWFLoader控件创建简单图片相册的例子
- Flex中如何利用focusIn和focusOut事件对表单中获得焦点的项目进行颜色高亮(highlight)显示的例子
- Flex中如何利用mx.utils.UIDUtil类的createUID()函数创建UID的例子
- 如何把Papervision3d物体加到 flex项目中(附 旋转圆球例子)
- Android对图片进行平移,缩放,旋转操作
- Flex中如何利用Camera.getCamera()和VideoDisplay#attachCamera()函数在VideoDisplay中显示用户摄像头内容
- Android单点触控对图片进行平移,缩放,旋转操作
- Java中list如何利用遍历进行删除操作
- Flex中如何通过addChild()函数在List中显示一个Sprite的例子
- 利用函数调用,对数组进行初始化,更改,清零,逆置等操作