刚看到这个要求时,虽然实现后的效果并不是多么炫,不过要实现这些简单的效果却真的让我有些茫然无措,用Google搜索了N久也没有看到一篇能够使用的Demo或Example,无奈之下只好从最基本也是最全面的资料--帮助文档分析起了,同时借鉴于ActionScritp3.0 CookBook的莫大帮助,才发现原来可以通过可视对象列表的叠加来实现,一点一点的磨损最终算是将一个很Ugly的图形放在了视频上,先把code粘到这,下一步的添加标题或边框应该就没有问题了。
Edit.mxml:(通过btnLoad按钮来添加叠放图形)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel x="10" y="10" width="403" height="385" layout="absolute">
<mx:VideoDisplay x="10" y="10" width="363" height="275" id="player" source="video/2.flv" autoPlay="false" borderColor="#0000ff" borderStyle="solid"/>
<mx:Button x="202" y="313" label="Play" id="btnPlay" click="player.play();"/>
<mx:Button x="286" y="313" label="Stop" id="btnStop" click="player.stop();"/>
<mx:Button x="105" y="313" label="Load" id="btnLoad" click="drawRect();"/>
</mx:Panel>
<mx:Script source="EditHandle.as"/>
<mx:Panel x="421" y="10" width="250" height="124" layout="absolute">
<mx:Button x="10" y="10" label="Merge" id="btnMer"/>
</mx:Panel>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel x="10" y="10" width="403" height="385" layout="absolute">
<mx:VideoDisplay x="10" y="10" width="363" height="275" id="player" source="video/2.flv" autoPlay="false" borderColor="#0000ff" borderStyle="solid"/>
<mx:Button x="202" y="313" label="Play" id="btnPlay" click="player.play();"/>
<mx:Button x="286" y="313" label="Stop" id="btnStop" click="player.stop();"/>
<mx:Button x="105" y="313" label="Load" id="btnLoad" click="drawRect();"/>
</mx:Panel>
<mx:Script source="EditHandle.as"/>
<mx:Panel x="421" y="10" width="250" height="124" layout="absolute">
<mx:Button x="10" y="10" label="Merge" id="btnMer"/>
</mx:Panel>
</mx:Application>
EditHandle.as:(Edit.mxml的脚本处理文件,只有其中的drawRect函数起作用,即绘制图形)
// ActionScript file
import mx.controls.VideoDisplay;
import mx.controls.videoClasses.CuePointManager;
import flash.text.TextField;
import snow.CircleExample;
private function displayCuePoint():void
{
//var proxy:CuePointManager=new CuePointManager(player.cuePointManager);
var cuePoints:Array=player.cuePoints;
trace("as");
for(var o:Object in cuePoints)
{
trace(o.name+":"+o.time);
}
}
//Did not function!
private function drawRect():void
{
//player.drawRoundRect(20,20,20,20,4,0xFF0000);
var obj:CircleExample=new CircleExample();
player.addChild(obj);
}
private function drawText():void
{
var field:TextField=new TextField();
field.text="Hello,I'm out!";
field.textColor=0xFF0000;
field.embedFonts=true;
field.x=30;
field.y=30;
player.addChild(field);
//DisplayObjectContainer(root).addChild(field);
//trace(root);
}
import mx.controls.VideoDisplay;
import mx.controls.videoClasses.CuePointManager;
import flash.text.TextField;
import snow.CircleExample;
private function displayCuePoint():void
{
//var proxy:CuePointManager=new CuePointManager(player.cuePointManager);
var cuePoints:Array=player.cuePoints;
trace("as");
for(var o:Object in cuePoints)
{
trace(o.name+":"+o.time);
}
}
//Did not function!
private function drawRect():void
{
//player.drawRoundRect(20,20,20,20,4,0xFF0000);
var obj:CircleExample=new CircleExample();
player.addChild(obj);
}
private function drawText():void
{
var field:TextField=new TextField();
field.text="Hello,I'm out!";
field.textColor=0xFF0000;
field.embedFonts=true;
field.x=30;
field.y=30;
player.addChild(field);
//DisplayObjectContainer(root).addChild(field);
//trace(root);
}
CircleExample.as:(绘制图形的类)
package snow
{
import flash.display.Sprite;
import flash.display.Shape;
public class CircleExample extends Sprite
{
public function CircleExample( )
{
// Create three different colored circles and
// change their coordinates so they are staggered
// and aren't all located at (0,0).
var red:Shape = createCircle( 0xFF0000, 10 );
red.x = 10;
red.y = 20;
var green:Shape = createCircle( 0x00FF00, 10 );
green.x = 15;
green.y = 25;
var blue:Shape = createCircle( 0x0000FF, 10 );
blue.x = 20;
blue.y = 20;
// First add the red circle, then add the blue circle (so blue
// is drawn on top of red)
addChild( red );
addChild( blue );
// Place the green circle between the red and blue circles
addChildAt( green, 1 );
}
// Helper function to create a circle shape with a given color
// and radius
public function createCircle( color:uint, radius:Number ):Shape
{
var shape:Shape = new Shape( );
shape.graphics.beginFill( color );
shape.graphics.drawCircle( 0, 0, radius );
shape.graphics.endFill( );
return shape;
}
}
}
{
import flash.display.Sprite;
import flash.display.Shape;
public class CircleExample extends Sprite
{
public function CircleExample( )
{
// Create three different colored circles and
// change their coordinates so they are staggered
// and aren't all located at (0,0).
var red:Shape = createCircle( 0xFF0000, 10 );
red.x = 10;
red.y = 20;
var green:Shape = createCircle( 0x00FF00, 10 );
green.x = 15;
green.y = 25;
var blue:Shape = createCircle( 0x0000FF, 10 );
blue.x = 20;
blue.y = 20;
// First add the red circle, then add the blue circle (so blue
// is drawn on top of red)
addChild( red );
addChild( blue );
// Place the green circle between the red and blue circles
addChildAt( green, 1 );
}
// Helper function to create a circle shape with a given color
// and radius
public function createCircle( color:uint, radius:Number ):Shape
{
var shape:Shape = new Shape( );
shape.graphics.beginFill( color );
shape.graphics.drawCircle( 0, 0, radius );
shape.graphics.endFill( );
return shape;
}
}
}
花了一下午的时间总算是有点收获,下来要做的事就是写一个通用的处理添加效果的类,这样在主程序中只需要将其对象通过addChild或addChildAt添加到VideoDisplay中即可。而对于对所添加对象的编辑,如文字字体,颜色,大小,方向等的设置,图象的大小,位置等的设置,都放在效果类中处理即可。