Flex 重复加载图片对内存和性能的影响
采用Image重复加载图片极大影响性能,并且占用大量内存,下面是我对比验证的代码。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
initialize="loadImage()">
<mx:Button x="122"
y="94"
label="add Low memory Images"
click="addLowMemImages()"/>
<mx:Button x="22"
y="94"
label="add Images"
click="addImages()"/>
<mx:Script>
<!--[CDATA[
import mx.controls.Image;
private var pairImage:BitmapData=new BitmapData(100, 100, false, 0x000000FF);
private function loadImage():void
{
var imageLoader:Loader=new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadComplete);
imageLoader.load(new URLRequest("pair.jpg"));
}
private function imageLoadComplete(event:Event):void
{
pairImage=event.target.content.bitmapData;
}
//低内存高性能方法
private function addLowMemImages():void
{
var canvas:Canvas;
for (var i:int=0; i < 30; i++)
{
for (var j:int=0; j < 30; j++)
{
canvas=new Canvas();
canvas.width=40;
canvas.height=40;
canvas.x=50 * i;
canvas.y=50 * j;
canvas.graphics.beginBitmapFill(pairImage);
canvas.graphics.drawRect(0, 0, 40, 40);
canvas.graphics.beginFill(0xFF0000, 0.5);
canvas.graphics.drawCircle(20, 20, 10);
canvas.graphics.endFill();
images.addChild(canvas);
}
}
}
//慢且占内存高
private function addImages()
{
var canvas:Canvas;
var img:Image;
for (var i:int=0; i < 10; i++)
{
for (var j:int=0; j < 10; j++)
{
canvas=new Canvas();
canvas.width=40;
canvas.height=40;
canvas.x=50 * i;
canvas.y=5
相关文档:
<?xml version="1.0" encoding="utf-8"?>
<!-- Simple example to demonstrate the DateTimeAxis class. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
......
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
<mx:Panel width="392" height="300" layout="absolute">
<mx:Label x="19" y="10" text="{user}" width="171" height="20"/>
<mx ......
发现了一个Flex中TextInput的一个比较有用的属性restrict(约束,限定),先看下例子:
1,<mx:TextInput id="test_ti" width="160" maxChars="20" restrict="0-9" text="0"/>
这样,这个输入框最多只能输入20个字符,只能输入0到9之间的数字了,你如果输入别的是输入不进去的
2,<mx:TextInput id="test_ti" width="1 ......
Flex Builder 3.0正式版:
http://download.macromedia.com/pub/flex/flex_builder/FB3_win.exe
或
http://www.adobe.com/cfusion/tdrc/index.cfm?product=flex
或
http://trials.adobe.com/Applications/Flex/FlexBuilder/3/FB3_WWEJ_Plugin.exe
AIR1.0 正式版:
http://airdownload.adobe.com/air ... ob ......
var login:infoChange=infoChange(PopUpManager.createPopUp( this, infoChange , true));
login.x=250;
login.y=150;
login.userid.text=dg.selectedItem.aa;
login.username.text=dg.selectedItem.bb;
......