独立于场景大小更改图像大小
我有三张图像,我想根据场景大小更改图像大小(默认大小为 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 函数。
也许我关于如何根据场景大小改变图像大小的想法是错误的。你会怎么做?
I have three images and I want change the images size based on the scene size (default size is 1024x768). After each image has completely loaded I call bindableUtils.setter to set width/height when scene size changes but I don't know how to make a pointer or something like that. I'm using a public var img, but it only works with the last complete image.
Here is my code:
<?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>
I don't use a for each image extra bindSetter function.
Maybe my idea on how I can change the size of image based on the size of the scene is wrong. How would you do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尝试过
percentWidth
和百分比高度
?did you try
percentWidth
andpercentHeight
?