2016-10-13 00:16:48 点击量:11 标签: 收藏本文
加载图片的例子,并且允许手工设置图片的宽和高
- <fx:Script>
- <![CDATA[
- protected function button1_clickHandler(event:MouseEvent):void
- {
- img.width = Number(imgWidth.text);
- img.height = Number(imgHeight.text);
- }
- ]]>
- </fx:Script>
- <fx:Declarations>
- <!-- 将非可视元素(例如服务、值对象)放在此处 -->
- </fx:Declarations>
- <mx:Image x="106" y="162" source="@Embed('/test/1.jpg')" width="211" height="182" id="img"/>
- <s:Button x="220" y="38" label="设置" click="button1_clickHandler(event)"/>
- <s:TextInput x="109" y="38" width="35" id="imgWidth"/>
- <s:TextInput x="162" y="38" width="35" id="imgHeight"/>
我把1.jpg放到test包里了,写路径的话就需要这么写:@Embed('/test/1.jpg'),不然可以会出现“无法解析用于转换代码”的错误;
Number()用于将给定值转换成数字值,用法很简单;
如果需要让图片加载的时候宽度和高度跟图片原始宽高度一样,可以这么写:<mx:Image x="106" y="162" source="@Embed('/test/1.jpg')" width="100%" height="100%" id="img" autoLoad="true" scaleContent="false"/>
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室