ActionScript 3 AS3:拖动n Drop

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3:拖动n Drop相关的知识,希望对你有一定的参考价值。

/*****************************
import Classes
*****************************/
import fl.video.FLVPlayback;
//Drag and Drop Manager
import flash.desktop.DragManager;
import flash.desktop.ClipboardFormats;
//Event that Handles the Drag and Drop Events
import flash.events.NativeDragEvent;


/*****************************
Create an active Hit Spot
*****************************/
var shape:Shape = new Shape();
	shape.graphics.beginFill(0x000000, 1);
	shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
	shape.graphics.endFill();

var _mc:MovieClip = new MovieClip();
	_mc.addChild(shape);
	addChild(_mc);

var video_vd:FLVPlayback = new FLVPlayback();
addChild(video_vd);
video_vd.x = 0;
video_vd.y = 0;
video_vd.width = 320;
video_vd.height = 240;


/*****************************
Drag and Drop
*****************************/
this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragEnter);
function onDragEnter(e:NativeDragEvent):void {
	//NativeDragEvent has a clipboard property where our data is stored. That clipboard class has a getData method
	//The way to specifiy formats is the a constant of a ClipboardFormats class. We just want a file object
	//The reason it is a filelist is because if multiple files were dragged into the Flash, all of them could be retreived
	var fa:Object = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT);
	//Check the File Extension of the Object
	if (fa[0].extension == "flv") {
		//Accept the Drag n Drop operation
		DragManager.acceptDragDrop(this);
	}
}

this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop);
function onDragDrop(e:NativeDragEvent):void {
	var fa:Object = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT);
	video_vd.play(fa[0].url);
}

以上是关于ActionScript 3 AS3:拖动n Drop的主要内容,如果未能解决你的问题,请参考以下文章

[ActionScript 3.0] as3处理xml的功能和遍历节点

ActionScript 3:使影片剪辑播放到最后

ActionScript 3 AS3 SWFtrospection(as3swf)

ActionScript 3 AS3 TextField和StyleSheet示例(在ActionScript中创建)

[ActionScript 3.0] AS3.0 水面波纹效果

ActionScript 3 AS3:使用SWFObject2和AS3传递变量