package com.huawei.bidc.customvisualcomp.combobox
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.utils.setTimeout;
import mx.controls.Alert;
import mx.controls.Image;
public class MyImage extends Image
{
//获得点击区域透明的对象
private var ht:Sprite = new Sprite();
public function MyImage()
{
addChild(ht);
hitArea = ht;
//设置透明部分不可见
ht.visible = false;
//设置透明部分鼠标事件无效
ht.mouseEnabled = false;
//没有手型样式
mouseChildren = false;
//添加监听器
this.addEventListener(Event.COMPLETE,complete,false,99,true);
//50毫秒执行一次
setTimeout(update,50);
}
//加载完毕执行函数
private function complete(e:Event):void
{
setTimeout(update,50)
}
private function update():void
{
//如果图片没有内容则返回
if(!content)
return;
//获得DisplayObject
var loader:DisplayObject = content.parent as DisplayObject;
//获得图片位图数据
var bit:BitmapData = new BitmapData(loader.width,loader.height,true,0x00000000);
//转换矩阵
var mat:Matrix = new Matrix();
//设置缩放和原图片一致
mat.scale(loader.scaleX,loader.scaleY);
bit.draw(loader,mat);
//重绘图像到ht上
ht.graphics.clear();
ht.graphics.beginFill(0);
for(var x:uint=0;x<bit.width;x++)
{
for(var y:uint=0;y<bit.height;y++)
{
//判断是否透明,透明则为0
if(bit.getPixel32(x,y))
{
ht.graphics.drawRect(x,y,1,1);
}
}
}
ht.graphics.endFill();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:components="com.huawei.bidc.customvisualcomp.combobox.*"
layout="vertical" backgroundGradientColors="[#FFFFFF, #FFFFFF]"
horizontalAlign="center" verticalAlign="middle" verticalScrollPolicy="off" horizontalScrollPolicy="off">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
[bindable]
private var poit_over:String = "";
[bindable]
private var poit_select:String = "";
//地图的点击事件
protected function mapItermclickHandler(event:MouseEvent):void
{
poit_select = "点击:x:"+event.localX+"y:"+event.localY;
Alert.show(poit_select);
// TODO Auto-generated method stub
// Alert.show(event.currentTarget.name+"***"+mapCanvas.getChildByName(event.currentTarget.name));
// initMapByKPI();
// Image(mapCanvas.getChildByName(event.currentTarget.name)).source = "assets/images/map/"+Image(mapCanvas.getChildByName(event.currentTarget.name)).id+"selected.png";
// analyseLabel = event.currentTarget.name;
// for(var i:int=0;i<areaArray.length;i++)
// {
// if(analyseLabel==areaArray.getItemAt(i).areaName)
// {
// mapAreaId =areaArray.getItemAt(i).areaId;
// break;
// }
// }
// areaAnalyseService.getAreaAnalyseClickData(mapAreaId,anlyseTime,doorWayString,chnlSelected);
// callLater(Default.setLoading);
}
//地图的点击事件
protected function mapItermmouseOverHandler(event:MouseEvent):void
{
poit_over = "经过:x:"+event.localX+"y:"+event.localY+"\n";
//Alert.show(poit_over);
}
]]>
</mx:Script>
<components:MyImage id="benxi" name="guangdong" source="assets/guangdong.png" x="745.2" y="195"
click="mapItermclickHandler(event)"
buttonMode="true" mouseOver="mapItermmouseOverHandler(event)"/>
<mx:TextArea text="{poit_over+poit_select}">
</mx:TextArea>
</mx:Application>