0

我有一个应用程序,我想拥有尽可能多的 FLV 播放器(每个播放器只播放一个视频),由 XML 控制。我控制一些变量(肤色、玩家 x 和 y 等)。我的代码正在运行,但有一些问题,所以我需要帮助来优化我的代码。一个问题是视频全屏,我把一个视频全屏,另一个全屏……还有皮肤 alpha 的其他问题,自动播放也发生了……

我的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);
4

2 回答 2

1
import fl.video.*;
import flash.events.ProgressEvent;
import fl.controls.ProgressBar;
import fl.controls.ProgressBarMode;

var my_videos:XMLList;
var my_total:Number;
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++) {

 var my_player:FLVPlayback = new FLVPlayback();
 my_player.name = "FLVplayer_" + i;
 my_player.skin = "SkinOverPlayFullscreen.swf";

 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;

 my_player.skinBackgroundColor = player_skin_color;
 my_player.skinBackgroundAlpha = player_skin_alpha;
 my_player.autoPlay = auto_play;

 my_player.source = my_videos[i].@URL;
 videoArray.push(my_player);

 addChild(my_player);
 }
}

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;

 }
}
于 2011-01-07T17:13:12.763 回答
0

每次添加 FLVPlayback 实例时,都会在 my_player 上创建它。

代替

my_player = new FLVPlayback();

尝试

//Create an array for the players
var my_players:Array = new Array();

//Add the player instances to the array
my_players.push (new FLVPlayback());

它应该解决其他问题。

于 2011-01-07T16:27:34.020 回答