Tree動態顯示Icon
MyIcon.as:
Test.mxml:
參照這篇文章寫的:
http://blog.chinaunix.net/u/21752/showart_2089230.html
package controls
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.TimerEvent;
import flash.net.URLRequest;
import flash.utils.Dictionary;
import flash.utils.Timer;
import mx.core.UIComponent;
import mx.skins.ProgrammaticSkin;
import mx.utils.NameUtil;
import mx.utils.StringUtil;
public class MyIcon extends ProgrammaticSkin
{
public static var showWaitIcon:Boolean = true;
private static var timer:Timer = null;
private static var bitmapDataIdList:Array = [];
private static var bitmapDatas:Dictionary = new Dictionary();
public static function getIconClass(target:UIComponent, url:String,
imageWidth:Number, imageHeight:Number):Class
{
url = StringUtil.trim(url);
imageWidth = (isNaN(imageWidth) ? 16 : imageWidth);
imageHeight = (isNaN(imageHeight) ? 16 : imageHeight);
var targetId:String = NameUtil.displayObjectToString(target);
var bitmapDataId:String = url + "(" + imageWidth + "*" + imageHeight + ")";
bitmapDataIdList.push({targetId: targetId, bitmapDataId: bitmapDataId});
if (!bitmapDatas[bitmapDataId])
bitmapDatas[bitmapDataId] = {url: url, imageWidth: imageWidth,
imageHeight: imageHeight, bitmapData: null};
return MyIcon;
}
public function MyIcon()
{
super();
if (!timer)
{
timer = new Timer(200);
timer.start();
}
timer.addEventListener(TimerEvent.TIMER, timerHandler);
addEventListener(Event.ADDED, addedHandler);
addEventListener(Event.REMOVED, removedHandler);
}
private var url:String = null;
private var imageWidth:Number = 16;
private var imageHeight:Number = 16;
private var bitmapDataId:String = null;
private var bitmapData:BitmapData = null;
override public function get measuredWidth():Number
{
return imageWidth;
}
override public function get measuredHeight():Number
{
return imageHeight;
}
private function requestImage():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
var request:URLRequest = new URLRequest(url);
loader.load(request);
}
override protected function updateDisplayList(w:Number, h:Number):void
{
graphics.clear();
if (isNaN(w) || isNaN(h))
return;
if (bitmapData)
{
graphics.beginBitmapFill(bitmapData, null, false, true);
graphics.drawRect(0, 0, w, h);
graphics.endFill();
return;
}
if (!showWaitIcon)
return;
drawWaitIcon(graphics, timer.currentCount % 8);
}
private function drawWaitIcon(g:Graphics, state:int):void
{
var color:uint = 0xE7E7E7;
var alpha:Number = 0.35;
var colors:Array = [0x6C7577, 0xC5CED0, 0xB9C1C3, 0xADB5B7,
0x9FA8AA, 0x929B9D, 0x868F90, 0x798284];
var alphas:Array = [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7];
var newColors:Array = [0, 0, 0, 0, 0, 0, 0, 0];
var newAlphas:Array = [0, 0, 0, 0, 0, 0, 0, 0];
var positions:Array = [{x: 0, y: 6}, {x: 2, y: 2}, {x: 6, y: 0}, {x: 10, y: 2},
{x: 12, y: 6}, {x: 10, y: 10}, {x: 6, y: 12}, {x: 2, y: 10}];
var i:int = 0;
var index:int = 0;
var x:Number = 0;
var y:Number = 0;
for (i = 0; i < 8; i++)
{
index = i + state;
index = (index >= 8 ? index - 8 : index);
newColors[index] = colors[i];
newAlphas[index] = alphas[i];
}
for (i = 0; i < 8; i++)
{
x = positions[i].x;
y = positions[i].y;
g.beginFill(color, alpha);
g.drawRect(x, y, 4, 4);
g.endFill();
g.beginFill(newColors[i], newAlphas[i]);
g.drawRect(x, y + 1, 4, 2);
g.endFill();
g.beginFill(newColors[i], newAlphas[i]);
g.drawRect(x + 1, y, 2, 4);
g.endFill();
}
}
private function addedHandler(event:Event):void
{
var targetId:String = NameUtil.displayObjectToString(parent);
var bitmapDataInfo:Object = null;
var i:int = 0;
for (i = bitmapDataIdList.length - 1; i >= 0; i--)
{
if (bitmapDataIdList[i].targetId == targetId ||
bitmapDataIdList[i].targetId == null)
{
bitmapDataId = bitmapDataIdList[i].bitmapDataId
bitmapDataInfo = bitmapDatas[bitmapDataId];
bitmapDataIdList.splice(i, 1);
}
}
if (bitmapDataInfo)
{
url = bitmapDataInfo.url;
imageWidth = bitmapDataInfo.imageWidth;
imageHeight = bitmapDataInfo.imageHeight;
bitmapData = bitmapDataInfo.bitmapData;
width = imageWidth;
height = imageHeight;
if (!bitmapData && url)
requestImage();
}
}
private function removedHandler(event:Event):void
{
if (timer)
timer.removeEventListener(TimerEvent.TIMER, timerHandler);
}
private function timerHandler(event:TimerEvent):void
{
updateDisplayList(measuredWidth, measuredHeight);
}
private function completeHandler(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
if (loaderInfo.content)
{
bitmapData = (loaderInfo.content as Bitmap).bitmapData;
bitmapDatas[bitmapDataId].bitmapData = bitmapData;
if (parent)
(parent as UIComponent).validateNow();
updateDisplayList(measuredWidth, measuredHeight);
}
}
private function ioErrorHandler(event:IOErrorEvent):void
{
}
}
}
Test.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import controls.MyIcon;
import mx.core.UIComponent;
private function treeIconFunction(data:Object):Class
{
if (!data)
return null;
if (!data.@icon)
return null;
return MyIcon.getIconClass(tree.itemToItemRenderer(data) as UIComponent, data.@icon, 16, 16);
}
]]>
</mx:Script>
<mx:XMLList id="treeData">
<item label="node1" icon="http://c.csdn.net/bbs/t/5/i/search1.gif">
<item label="node2" icon="http://topic.csdn.net/u/ui/images/blank.gif" />
<item label="node3" icon="http://csdnimg.cn/bbs/m/i/yellow_1.gif" />
<item label="node4" icon="http://csdnimg.cn/www/images/dnspic_csdn.gif">
<item label="node5" icon="http://csdnimg.cn/www/images/csdnindex_pic1.gif" />
<item label="node6" icon="http://csdnimg.cn/www/images/csdnindex_pic2.gif" />
</item>
</item>
<item label="node7" icon="http://csdnimg.cn/bbs/m/i/red_2.gif" />
</mx:XMLList>
<mx:Tree id="tree" width="200" height="200" dataProvider="{treeData}"
labelField="@label" iconFunction="treeIconFunction" />
</mx:Application>
參照這篇文章寫的:
http://blog.chinaunix.net/u/21752/showart_2089230.html
相關文章
- vue3 動態載入el-icon圖示Vue
- 數碼管動態顯示
- 靜態數碼管顯示、動態數碼管顯示、矩陣按鍵矩陣
- 動態修改應用icon和name
- javaScript動態顯示當前時間JavaScript
- jqgrid動態顯示,隱藏指定列
- [Java Swing] 在mac中不顯示java的dock iconJavaMac
- Vue引入icon圖示Vue
- vue中:is的用法,動態顯示需要的元件Vue元件
- icon 圖示css實現CSS
- iOS神技之動態更換APP的Icon圖iOSAPP
- 在 Laravel 中動態 隱藏 / 顯示 API 欄位LaravelAPI
- 動態的新增ImageView到LinearLayout中並居中顯示View
- 中斷與數碼管動態顯示程式碼
- Cell 動態行高文字顯示不全問題探索
- SAP ABAP 動態內表實現 ALV橫向按月份動態顯示資料
- Symbol 引用 iconfont icon圖示庫Symbol
- layui 輪播圖動態資料不顯示問題UI
- WIN10動態磁貼不顯示內容怎麼設定 WIN10設定動態磁貼不顯示內容方法Win10
- uview2.0版本,h5內網,無網路下icon圖示不顯示ViewH5內網
- elementui 如果變數為1 顯示 開啟,2顯示關閉。表格怎麼根據狀態碼顯示狀態值UI變數
- 手把手教你完成數字動態變化顯示效果
- Element 利用Tooltip提示框實現動態顯示文字提示
- 動態顯示:文字框字數(輸入還剩多少字)
- Macicon圖示製作——Icon Resize for MacMac
- 【資料】靜態/動態顯示LCD液晶驅動晶片VKS232,116SEG*2COM晶片
- 表格顯示滾動條
- 動態控制C4C UI元素的顯示和隱藏UI
- element-plus el-table 動態設定列顯示隱藏
- 影片直播app原始碼,Swift動態修改Icon,消除系統彈窗APP原始碼Swift
- SAP CRM頁面assignment block動態顯示與否的控制邏輯BloC
- 超出文字顯示省略號,hover效果:文字滾動顯示==》求解
- Python PyQt顯示臨時狀態訊息PythonQT
- react-native Android使用阿里icon font圖示ReactAndroid阿里
- 三種動態控制SAP CRM WebClient UI assignment block顯示與否的方法WebclientUIBloC
- 圖表外掛Highcharts的動態化賦值,實現圖表資料的動態化設定顯示賦值
- 顯示卡驅動有必要更新嗎 顯示卡驅動怎麼更新詳細教程
- web 多屏互動顯示方案Web
- Android程式啟動與Activity顯示Android