我很难过。我有两个我正在创作的flash文件。
文件A在舞台上有一个MovieClip,它与我导入fl.video.FLVPlayback的类有链接 文件B还尝试导入fl.video.FLVPlayback。
文件B抛出COMPILE TIME错误,无法找到fl.video.FLVPlayback的定义。我注意到我的FlashDevelop也没有提供该行的语法高亮。
两者都导出相同版本的FlashPlayer(10)。两者都是在同一平台上编写的,相同的软件(CS4)。我没有搞乱任何发布设置,除了文件B与文档类相关联。
感兴趣的是,文件A最终将被加载到文件B中,进入文件B的上下文。
什么事?我不知道从哪里开始寻找。
提前致谢。
答案 0 :(得分:10)
如果您没有使用FLVPlayback组件(从组件库拖到舞台上),那么Flash无法开箱即可访问fl包。
您必须在类路径中包含组件源文件夹或.swc(源文件夹将位于"源路径" as3发布设置的选项卡,&#34中的.swc ;图书馆路径"标签),以便您的班级工作。
源文件夹是: C:\ Program Files(x86)\ Adobe \ Adobe Flash CS4 \ Common \ Configuration \ Component Source \ ActionScript 3.0 \ FLVPlayback
.swc位于以下目录中: C:\ Program Files(x86)\ Adobe \ Adobe Flash CS4 \ Common \ Configuration \ Components \ Video
swc可能更容易包含,因为您可以根据需要将.swc直接复制并粘贴到项目文件夹中。
答案 1 :(得分:3)
基于Sapptime的回答,我想补充一点,您可以在“发布设置”下创建不同的配置文件。
因此,您可以通过导入.swc文件来创建包含FLVPlayback组件的配置文件,并在需要使用FLVPlayer时使用该配置文件。向项目添加大约100 KB。
这样您就不需要在库中或舞台上使用FLVPlayback组件。相反,您可以像项目中的任何其他类一样导入FLVPlayback类,并在动作脚本代码中创建FLVPlayback实例。
//import:
import fl.video.FLVPlayback;
//Instantiate:
private var player:FLVPlayback = new FLVPlayback();
我已经添加了一个Videoplayer.as类(因为我找不到附加它的方法)我为一个项目做了一个项目并快速剥离了一些额外的内容,但它应该可以工作:)随意使用它是原样,修改它或获得一些灵感。
将Videoplayer.as放在项目的src文件夹中,并创建一个新实例。使用setter来控制它。
//Instantiate
var MyPLayer:Videoplayer = new Videoplayer();
//Use setters
MyPLayer.SetVideopath = path to flv file;
MyPLayer.SetVideoAutoplay = true; // or false
//... and so on
// add to displaylist
this.addChild(MyPlayer);
// Load video
MyPlayer.Load();
// start playing
MyPlayer.Play();
这是Videoplayer类...
package {
import fl.video.*;
import flash.events.*;
import flash.display.Sprite;
import flash.display.Shape;
public class Videoplayer extends Sprite {
// VIDEO
private var player:FLVPlayback = new FLVPlayback();
private static var videoPath:String="";
private var w:Number = 1280;
private var h:Number = 720;
private var vol:Number = 0;
private var autoplay:Boolean = false;
private var autorewind:Boolean = false;
private var Loop:Boolean = false;
private var bgcolor:uint = 0x000000;
private var HasError:Boolean=false;
private var playerid:Number;
private var SeekSecToStop:Number=0;
private var BufferTime:Number=0;
private var videoBG:Shape;
// ===============================================================================================
// CONSTRUCTOR
// ===============================================================================================
public function Videoplayer() {
super();
trace("Videoplayer");
this.addChild(player);
player.addEventListener(VideoEvent.STATE_CHANGE, VidState, false, 0, true);
player.addEventListener(VideoEvent.READY, VidReady, false, 0, true);
player.addEventListener(VideoEvent.AUTO_REWOUND, VidRewinded, false, 0, true);
player.addEventListener(VideoEvent.STOPPED_STATE_ENTERED, VidStopped, false,0,true);
}
// ===============================================================================================
// SET VIDEO PROPS
// ===============================================================================================
private function setVidProps():void {
player.name = "player";
player.skinBackgroundColor = getVideoBGcolor;
player.skinBackgroundAlpha = 0;
player.registrationX = 0;
player.registrationY = 0;
player.setSize(getVideoWidth,getVideoHeight);
player.scaleMode = "maintainAspectRatio"; // exactFit, noScale, maintainAspectRatio
//player.fullScreenTakeOver = false;
player.isLive = false;
player.bufferTime = BufferTime;
player.autoRewind = getVideoAutorewind;
player.volume = vol;
}
// ===============================================================================================
// LOAD
// ===============================================================================================
public function Load():void {
trace("Load");
setVidProps();
player.source = getVideopath;
}
// ===============================================================================================
// PLAY
// ===============================================================================================
public function Play():void {
player.playWhenEnoughDownloaded();
UnMute();
}
public function Pause():void {
player.pause();
}
public function Stop():void {
//player.seek(SeekSecToStop);
player.stop();
//player.pause();
}
public function SeekAndStop():void {
player.seek(SeekSecToStop);
player.pause();
}
public function SeekAndPlay(n:Number=0):void {
player.seek(n);
Play();
}
public function Fullscreen():void {
//player.fullScreenTakeOver = true;
//player
}
public function Mute():void {
player.volume = 0;
}
public function UnMute():void {
player.volume = 1;
}
public function Volume(n:Number):void {
player.volume=n;
}
// ===============================================================================================
// VidReady
// ===============================================================================================
private function VidReady(e:Event):void {
trace("VidReady");
//player.removeEventListener(VideoEvent.READY, VidReady);
player.fullScreenTakeOver = false;
if (autoplay) {
player.autoPlay = autoplay;
Play();
} else {
player.play();
SeekAndStop();
}
dispatchEvent(new VideoEvent(VideoEvent.READY));
}
// ===============================================================================================
// VidStopped
// ===============================================================================================
private function VidStopped(e:Event):void {
trace("VidStopped");
//dispatchEvent(new VideoEvent(VideoEvent.STOPPED));
if(Loop) {
//SeekAndPlay();
Play();
} else {
dispatchEvent(new VideoEvent(VideoEvent.STOPPED_STATE_ENTERED));
}
}
// ===============================================================================================
// VidRewinded
// ===============================================================================================
private function VidRewinded(e:Event):void {
trace("VidRewinded");
}
// ===============================================================================================
// VidState
// ===============================================================================================
private function VidState(e:Event):void {
var flvPlayer:FLVPlayback = e.currentTarget as FLVPlayback;
//Log("VideoState 1 : "+flvPlayer.state);
if (flvPlayer.state==VideoState.CONNECTION_ERROR) {
trace("FLVPlayer Connection Error! -> path : "+flvPlayer.source);
//dispatchEvent(new VideoEvent(VideoEvent.CONNECTION_ERROR));
HasError=true;
//CleanUp();
} else if (flvPlayer.state==VideoState.BUFFERING) {
trace("BUFFERING");
} else if (flvPlayer.state==VideoState.DISCONNECTED) {
trace("DISCONNECTED");
} else if (flvPlayer.state==VideoState.LOADING) {
trace("LOADING");
} else if (flvPlayer.state==VideoState.PAUSED) {
trace("PAUSED");
} else if (flvPlayer.state==VideoState.RESIZING) {
trace("RESIZING");
} else if (flvPlayer.state==VideoState.REWINDING) {
trace("REWINDING");
} else if (flvPlayer.state==VideoState.SEEKING) {
trace("SEEKING");
} else if (flvPlayer.state==VideoState.PLAYING) {
trace("PLAYING");
} else if (flvPlayer.state==VideoState.STOPPED) {
trace("STOPPED");
//flvPlayer.pause();
} else if (flvPlayer.state==VideoState.RESIZING) {
trace("RESIZING");
}
}
// ===============================================================================================
// SETTERS & GETTERS
// ===============================================================================================
public function set SetPlayerId(n:Number):void {
playerid=n;
}
public function get getPlayerId():Number {
return playerid;
}
public function set SetSeekSecToStop(n:Number):void {
SeekSecToStop=n;
}
public function get getSeekSecToStop():Number {
return SeekSecToStop;
}
public function set SetVideoLoop(b:Boolean):void {
Loop = b;
}
public function get getVideoLoop():Boolean {
return Loop;
}
public function set SetVideoAutorewind(b:Boolean):void {
autorewind = b;
}
public function get getVideoAutorewind():Boolean {
return autorewind;
}
public function set SetVideoAutoplay(b:Boolean):void {
autoplay = b;
}
public function get getVideoAutoplay():Boolean {
return autoplay;
}
public function set SetVideopath(s:String):void {
videoPath = s;
}
public function get getVideopath():String {
return videoPath;
}
public function set SetVideoWidth(n:Number):void {
w = n;
}
public function get getVideoWidth():Number {
return w;
}
public function set SetVideoHeight(n:Number):void {
h = n;
}
public function get getVideoHeight():Number {
return h;
}
public function set SetVideoBGcolor(n:uint):void {
bgcolor = n;
}
public function get getVideoBGcolor():uint {
return bgcolor;
}
public function get getPlayerState():String {
return player.state;
}
public function get GetHasError():Boolean {
return HasError;
}
}
}
答案 2 :(得分:2)
您需要确保库中存在 FLVPlayback 组件并导出为ActionScript(应该是默认设置)。
要将其添加到库中,只需打开组件面板(窗口 - >组件),然后展开名为视频的组,在库中拖动 FLVPlayback 。无需把它放在舞台上。
默认情况下应将其导出为“ fl.video.FLVPlayback ”。
干杯