簡體   English   中英

Flash AS3 Tweelite和XML問題

[英]Flash AS3 Tweelite and XML Issue

我有一個兩幀Flash CS3動畫。 在第一幀上,我(成功地)將四個圖像加載到該幀上,並使用TweenLite(成功地)在它們之間旋轉。 當用戶單擊按鈕時,將設置變量(resumeVideoOn)來指示用戶正在查看的當前圖像,然后將它們帶到第2幀,播放相應的視頻。 視頻播放完畢后,用戶可以選擇單擊一個按鈕以重新播放視頻,或者單擊一個按鈕以將其帶回到frame1(通過簡單的gotoAndPlay(1)調用)。 當用戶返回到frame1時,我檢測到“ resumeVideoOn”的值,以確定恢復動畫循環的功能。 它將正確加載初始圖像。 但是,盡管它繼續運行一系列功能(由於跟蹤以及這些功能中調用的其他補間正在正常工作,我可以知道),但僅顯示您返回的原始圖像(其他三個圖像正在顯示)。由TweenLite調用不會出現)。 我已經對此轉了一圈了。 下面是一些代碼,盡管有很多,所以我嘗試只放入必要的內容:

// pull in images and video properties thru XML
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("flash.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();
    if(my_total > 0) {
        makeContainers();
        callImgs();
    } else {
        trace("put alternate case here in case nothing is loaded");        
    }
}

function makeContainers():void {
    main_container = new Sprite();
    addChild(main_container);

    main_container.addChild(image1);
    main_container.addChild(image2);
    main_container.addChild(image3);
    main_container.addChild(image4);

    setChildIndex(DisplayObjectContainer(main_container),0);
}

function callImgs():void {
    var img_loader1 = new Loader();
    img_loader1.load(new URLRequest(my_videos[0].@IMG));
    image1.addChild(img_loader1);
    wtv1 = my_videos[0].@WTVPOS;
    video1 = my_videos[0].@VIDURL;

    var img_loader2 = new Loader();
    img_loader2.load(new URLRequest(my_videos[1].@IMG));
    image2.addChild(img_loader2);
    wtv2 = my_videos[1].@WTVPOS;
    video2 = my_videos[1].@VIDURL;

    var img_loader3 = new Loader();
    img_loader3.load(new URLRequest(my_videos[2].@IMG));
    image3.addChild(img_loader3);
    video3 = my_videos[2].@VIDURL;
    wtv3 = my_videos[2].@WTVPOS;

    var img_loader4 = new Loader();
    img_loader4.load(new URLRequest(my_videos[3].@IMG));
    image4.addChild(img_loader4);
    wtv4 = my_videos[3].@WTVPOS;
    video4 = my_videos[3].@VIDURL;
}

function imgLoaded(e:Event):void {
    var my_img:Loader = Loader(e.target.loader);
    image1.addChild(my_img);
}


//tween and go to video on frame 2 if clicked on myFrame1()
function myFrame1():void {
    //image 1
    image1.alpha = 100;// start faded down

    TweenLite.to(selectedFrame, 1, {x:501.6, overwrite:1});
    TweenLite.to(image1, 1, {alpha:0, delay:3, overwrite:0});
    TweenLite.to(image2, 1, {alpha:1, delay:3, overwrite:0});
    //wtv1
    if(wtv1 == "right") {
        TweenLite.to(watchthevideo_right_mc, 1, {alpha:1});
        watchthevideo_right_mc.addEventListener(MouseEvent.CLICK, playVideo1);
        TweenLite.to(watchthevideo_right_mc, 1, {alpha:0, delay:3, overwrite:0, onComplete:myFrame2});
    } else {
        TweenLite.to(watchthevideo_left_mc, 1, {alpha:1});
        watchthevideo_left_mc.addEventListener(MouseEvent.CLICK, playVideo1);
        TweenLite.to(watchthevideo_left_mc, 1, {alpha:0, delay:3, overwrite:0, onComplete:myFrame2});
    }
}

function playVideo1(e:MouseEvent):void {
    //kill all tweens
    TweenLite.killTweensOf(watchthevideo_right_mc);
    TweenLite.killTweensOf(watchthevideo_left_mc);
    TweenLite.killTweensOf(image1);
    TweenLite.killTweensOf(image2);
    TweenLite.killTweensOf(image3);
    TweenLite.killTweensOf(image4);
    videoFile = video1;
    resumeVideoOn = 1;
    gotoAndPlay(2);
}

// on frame 2
// after video is played
function returnShow(e:MouseEvent):void {
    TweenLite.to(_replayButton, 1, {alpha:0, overwrite:0});
    TweenLite.to(_returnButton, 1, {alpha:0, overwrite:0});
    _replayButton.visible = false;
    _returnButton.visible = false;
    TweenLite.to(rectangle, 1, {alpha:0, overwrite:0});

    //reset all video data
    removeChild(video);
    removeChild(pause_mc);
    removeChild(play_mc);
    removeChild(volslide_mc);
    removeChild(controls_mc);
    removeChild(controlBacker_mc);
    removeChild(_replayButton);
    removeChild(_returnButton);

    gotoAndPlay(1);
}

// when the user returns to frame 1, the variable 'resumeVideoOn' is checked 
// in an if statement to determine where to resume.  the if statement is run, 
// then goes to function myFrame2 (or whatever the next frame is), but the image
// is not changing

另外,我的xml文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<MYLIST>
<VIDEO VIDURL="videos/video1.flv" WTVPOS="right" IMG="imgs/image1.jpg" />
<VIDEO VIDURL="videos/video2.flv" WTVPOS="left" IMG="imgs/image2.jpg" />
<VIDEO VIDURL="videos/video3.flv" WTVPOS="right" IMG="imgs/image3.jpg" />
<VIDEO VIDURL="videos/video4.flv" WTVPOS="left" IMG="imgs/image4.jpg" />
</PHHLIST>

剛弄清楚,對於任何關心的人...我需要添加一個

removeChild(main_container);

到將用戶發送到第2幀的功能。當我拖動顯示窗口大於視頻窗口時,我可以看到原始圖像仍在舞台上,從而阻止了用戶返回第1幀時顯示的任何圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM