使用 XML 和 For 循环的 Actionscript 3 FlvPlayback

发布于 2024-10-10 17:30:49 字数 2801 浏览 2 评论 0原文

我有一个应用程序,我想要有尽可能多的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思念满溢 2024-10-17 17:30:49
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;

 }
}
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;

 }
}
予囚 2024-10-17 17:30:49

每次添加 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());

它应该解决其他问题。

every time you add an FLVPlayback instance you create it on my_player.

instead of

my_player = new FLVPlayback();

try

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

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

It should solve the other issues.

Rob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文