【发布时间】:2011-04-07 02:59:04
【问题描述】:
我有三张图像,我想根据场景大小更改图像大小(默认大小为 1024x768)。在每个图像完全加载后,当场景大小发生变化时,我调用 bindableUtils.setter 来设置宽度/高度,但我不知道如何制作指针或类似的东西。我正在使用公共 var img,但它仅适用于最后一个完整的图像。
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.binding.utils.BindingUtils;
public var img:Image;
private function setterWidth(newWidth:Number):void
{
img.width = img.content.width * newWidth / 1024;
}
private function setterHeight(newHeight:Number):void
{
img.height = img.content.height * newHeight / 768;
}
protected function image_completeHandler(event:Event):void
{
img = event.target as Image;
BindingUtils.bindSetter(setterWidth, this, "width");
BindingUtils.bindSetter(setterHeight, this, "height");
}
]]>
</fx:Script>
<mx:Image id="img1" source="img1.jpg" complete="image_completeHandler(event)" />
<mx:Image id="img2" source="img2.jpg" complete="image_completeHandler(event)" y="60"/>
<mx:Image id="img3" source="img3.jpg" complete="image_completeHandler(event)" y="120"/>
</s:Application>
我没有为每个图像使用额外的 bindSetter 函数。
也许我关于如何根据场景大小更改图像大小的想法是错误的。你会怎么做?
【问题讨论】:
标签: apache-flex actionscript-3 mxml