使用 XML 和 For 循环的 Actionscript 3 FlvPlayback
我有一个应用程序,我想要有尽可能多的 FLV 播放器(每个播放器只播放一个视频),由 XML 控制。我控制一些变量(肤色、玩家 x 和 y 等)。 我的代码可以工作,但存在一些问题,因此我需要帮助来优化我的代码。 其中一个问题是全屏视频,我将一个视频全屏,另一个视频全屏...以及皮肤阿尔法的其他问题,自动播放也会发生..
我的 AS3
import fl.video.*;
import flash.events.ProgressEvent;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;
var my_videos:XMLList;
var my_total:Number;
var my_player:FLVPlayback;
var player_skin_color:Number;
var player_skin_alpha:Number;
var auto_play:Boolean;
var videoArray:Array = new Array();
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("test.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML = new XML(e.target.data);
my_videos = myXML.VIDEO;
my_total = my_videos.length();
makePlayer();
positionPlayer();
}
function makePlayer():void {
for (var i:int = 0; i < my_total; i++) {
my_player = new FLVPlayback();
my_player.skin = "SkinOverPlayFullscreen.swf";
my_player.skinBackgroundColor = player_skin_color;
my_player.skinBackgroundAlpha = player_skin_alpha;
my_player.autoPlay = auto_play;
player_skin_color = my_videos[i]. @ PLAYER_SKIN_COLOR;
player_skin_alpha = my_videos[i]. @ PLAYER_SKIN_ALPHA;
auto_play = my_videos[i]. @ VIDEO_AUTOPLAY;
addChild(my_player);
videoArray.push(my_player);
my_player.source = my_videos[i]. @ URL;
}
}
function positionPlayer():void {
for (var i:int = 0; i < my_total; i++)
{
videoArray[i].x = my_videos[i] . @PLAYER_X;
videoArray[i].y = my_videos[i] . @PLAYER_Y;
videoArray[i].width = my_videos[i] . @PLAYER_WIDTH;
videoArray[i].height = my_videos[i] . @PLAYER_HEIGHT;
}
}
我的 XML
<?xml version="1.0" encoding="utf-8"?>
<content>
<VIDEO PLAYER_X="450" PLAYER_Y="0" PLAYER_WIDTH="400" PLAYER_HEIGHT="300" PLAYER_SKIN_COLOR="0x0000FF" PLAYER_SKIN_ALPHA="1" VIDEO_AUTOPLAY="true" URL="test.flv"></VIDEO>
<VIDEO PLAYER_X="0" PLAYER_Y="0" PLAYER_WIDTH="400" PLAYER_HEIGHT="300" PLAYER_SKIN_COLOR="0x333333" PLAYER_SKIN_ALPHA="1" VIDEO_AUTOPLAY="true" URL="test2.flv"></VIDEO>
</content>
更新:
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
function goFullScreen():void
{
if (stage.displayState == StageDisplayState.NORMAL) {
stage.displayState=StageDisplayState.FULL_SCREEN;
} else {
stage.displayState=StageDisplayState.NORMAL;
}
}
//GREENSOCK LIQUID LAYOUT
var ls:LiquidStage = new LiquidStage(this.stage,900,600,900,600);
ls.attach(video_container_mc, ls.CENTER, false, true, 0);
I have a aplication and I want to have as many FLV players(to play only one video each) as I want, controled by XML. I control some variables (skin color, player x and y, etc).
My code is working but with some problems, so I need help to optimize my code.
One of the problem is on videos fullscreen, I put one video in Fullscreen, and the other goes to full screen...and other problems with skin alpha, autoplay happens too..
My AS3
import fl.video.*;
import flash.events.ProgressEvent;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;
var my_videos:XMLList;
var my_total:Number;
var my_player:FLVPlayback;
var player_skin_color:Number;
var player_skin_alpha:Number;
var auto_play:Boolean;
var videoArray:Array = new Array();
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("test.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
var myXML:XML = new XML(e.target.data);
my_videos = myXML.VIDEO;
my_total = my_videos.length();
makePlayer();
positionPlayer();
}
function makePlayer():void {
for (var i:int = 0; i < my_total; i++) {
my_player = new FLVPlayback();
my_player.skin = "SkinOverPlayFullscreen.swf";
my_player.skinBackgroundColor = player_skin_color;
my_player.skinBackgroundAlpha = player_skin_alpha;
my_player.autoPlay = auto_play;
player_skin_color = my_videos[i]. @ PLAYER_SKIN_COLOR;
player_skin_alpha = my_videos[i]. @ PLAYER_SKIN_ALPHA;
auto_play = my_videos[i]. @ VIDEO_AUTOPLAY;
addChild(my_player);
videoArray.push(my_player);
my_player.source = my_videos[i]. @ URL;
}
}
function positionPlayer():void {
for (var i:int = 0; i < my_total; i++)
{
videoArray[i].x = my_videos[i] . @PLAYER_X;
videoArray[i].y = my_videos[i] . @PLAYER_Y;
videoArray[i].width = my_videos[i] . @PLAYER_WIDTH;
videoArray[i].height = my_videos[i] . @PLAYER_HEIGHT;
}
}
My XML
<?xml version="1.0" encoding="utf-8"?>
<content>
<VIDEO PLAYER_X="450" PLAYER_Y="0" PLAYER_WIDTH="400" PLAYER_HEIGHT="300" PLAYER_SKIN_COLOR="0x0000FF" PLAYER_SKIN_ALPHA="1" VIDEO_AUTOPLAY="true" URL="test.flv"></VIDEO>
<VIDEO PLAYER_X="0" PLAYER_Y="0" PLAYER_WIDTH="400" PLAYER_HEIGHT="300" PLAYER_SKIN_COLOR="0x333333" PLAYER_SKIN_ALPHA="1" VIDEO_AUTOPLAY="true" URL="test2.flv"></VIDEO>
</content>
UPDATE:
import flash.display.StageDisplayState;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
function goFullScreen():void
{
if (stage.displayState == StageDisplayState.NORMAL) {
stage.displayState=StageDisplayState.FULL_SCREEN;
} else {
stage.displayState=StageDisplayState.NORMAL;
}
}
//GREENSOCK LIQUID LAYOUT
var ls:LiquidStage = new LiquidStage(this.stage,900,600,900,600);
ls.attach(video_container_mc, ls.CENTER, false, true, 0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每次添加 FLVPlayback 实例时,都会在 my_player 上创建它。
而不是
尝试
它应该解决其他问题。
抢
every time you add an FLVPlayback instance you create it on my_player.
instead of
try
It should solve the other issues.
Rob