用法:如果是把png直接导入flash转换成影片剪辑,只需在影片剪辑属性中勾选为ActionScript导出(x),并把基类里的flash.display.MovieClip替换成InteractivePNG即可;如果是外部导入png,只需将存放png的类继承InteractivePNG即可;

 package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.DropShadowFilter;
import flash.net.URLRequest; /**
* ...
* @author Frost.Yen
*/
public class TestPNG extends Sprite
{
private var pngSp:PNGContainer;
private var ldr:Loader = new Loader ;
private var lineSp:Sprite;
private var frame:Shape = new Shape ;
public function TestPNG()
{ lineSp = new Sprite ;
pngSp = new PNGContainer ;
pngSp.x = pngSp.y = 200;
this.addChild(lineSp);
this.addChild(pngSp);
pngSp.addEventListener(MouseEvent.MOUSE_OVER,onPNGOver);
pngSp.addEventListener(MouseEvent.MOUSE_OUT,onPNGOut);
} private function onPNGOver(e:MouseEvent):void
{
drawLine(pngSp);
} private function onPNGOut(e:MouseEvent):void
{
this.removeChild(frame);
} private function drawLine(_mc:MovieClip)
{
frame.graphics.clear();
frame.graphics.moveTo(_mc.x,_mc.y);
frame.graphics.lineStyle(1,0xff00ff);
frame.graphics.lineTo(_mc.x + _mc.width,_mc.y);
frame.graphics.moveTo(_mc.x + _mc.width,_mc.y);
frame.graphics.lineTo(_mc.x + _mc.width,_mc.y + _mc.height);
frame.graphics.moveTo(_mc.x + _mc.width,_mc.y + _mc.height);
frame.graphics.lineTo(_mc.x,_mc.y + _mc.height);
frame.graphics.moveTo(_mc.x,_mc.y + _mc.height);
frame.graphics.lineTo(_mc.x,_mc.y);
addChild(frame);
}
}
}
 package
{
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest; /**
* ...
* @author Frost.Yen
*/
public class PNGContainer extends InteractivePNG
{
private var ldr:Loader = new Loader ;
public function PNGContainer()
{
ldr.load(new URLRequest("128.png"));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,onPNGLoaded);
} private function onPNGLoaded(e:Event):void
{
this.addChild(e.target.content);
}
} }

InteractivePNG.as类可以到http://yan_frost.download.csdn.net/下载

05-11 21:51