AS3:如何使用两个参数调用函数 - (vBox和vFile)

时间:2015-03-29 20:22:36

标签: function actionscript-3 flash desktop flvplayback

  

Adob​​e Flash CC

这里有点困惑。我正在努力优化我的代码,而不是调用launchVideo();对于每个视频,我可以简单地调用一次,同时将新的源字符串传递给函数。

如何在另一个函数中调用launchVideo函数?

当我添加一个调用playMPMovie

的事件监听器时
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, playMPMovie, false, 0, true);
function playMPMovieOne(): void {
    video_file = "/videos/MP_01.mp4";
    launchVideo();
}

我明白了......

Scene 1, Layer 'actions', Frame 1, Line 21, Column 2    1136: Incorrect number of arguments.  Expected 2.

当我尝试将(vBox,vFile)添加到launchVideo()时;我明白了......

Scene 1, Layer 'actions', Frame 1, Line 20, Column 20   1120: Access of undefined property vFile.
Scene 1, Layer 'actions', Frame 1, Line 20, Column 14   1120: Access of undefined property vBox.

这是完整的代码。

stop();

import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Graphics;
import fl.video.*;


vinetteMC.visible = false;

// VARIABLES //
var video_holder: MovieClip = new MovieClip();
var video_file: String;

// EVENT LISTENERS //
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, playMPMovie, false, 0, true);
function playMPMovieOne(): void {
    video_file = "/videos/MP_01.mp4";
    launchVideo();
}

// Place Playback
function launchVideo(vBox, vFile): void {

    var flvPlayer: FLVPlayback = new FLVPlayback();
    import fl.video.*;
    import flash.events.*;

    flvPlayer.source = vFile;
    flvPlayer.skinAutoHide = true;
    flvPlayer.skinBackgroundColor = 0x000000;

    flvPlayer.width = 1920;
    flvPlayer.height = 1080;

    flvPlayer.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
    function completeHandler(event: Event): void {

        removeChild(video_holder);
        removeChild(flvPlayer);
        flvPlayer.addEventListener(fl.video.VideoEvent.COMPLETE, completeHandler, false, 0, true);
        trace("Complete handler called");
    }

    vBox.addChild(flvPlayer);
}

launchVideo(video_holder, video_file);

1 个答案:

答案 0 :(得分:0)

看起来你想打电话

function playMPMovieOne(): void {
    video_file = "/videos/MP_01.mp4";
    launchVideo(video_holder, video_file)
}

同样从您的示例代码中创建了视频持有者,但从未添加到显示列表中。您可能需要添加此内容以查看任何内容。

addChild(video_holder);