Flash CS6 - Actionscript 3 - 加载SWF - 只播放一个

时间:2013-05-26 07:36:46

标签: actionscript-3 flash-cs6

我只是在试图让导航栏工作,我遇到了麻烦。我有一个main.swf,其中包含加载circle.swfsquare.swftriangle.swf各自按钮点击的代码。圆形和方形加载并正确播放,但三角形加载,但由于某种原因不起作用。在我看来,代码对于这三个代码是相同的,但只有那个代码不起作用。

请注意确定错误的确切位置,但在其下方是指代特定swfs的代码。请告诉我,看看它是否有帮助。

var _swfPathArr:Array = new Array("Subfolder/Circle.swf", "Subfolder/Subsubfolder/Square.swf", "Triangle.swf");

button_Circle.addEventListener(MouseEvent.CLICK, setContent);
button_Square.addEventListener(MouseEvent.CLICK, setContent);
button_Triangle.addEventListener(MouseEvent.CLICK, setContent);

实际显示并清除加载的swfs的方法:

function setContent(event:MouseEvent):void
{
    var _swfToAdd:MovieClip;

    switch(event.target.name)
    {
        case "button_Circle":
        _swfToAdd = _swfClipsArr[0];
        gotoAndStop(2);
        break;

        case "button_Square":
        _swfToAdd = _swfClipsArr[1];
        gotoAndStop(3);
        break;

        case "button_Triangle":
        _swfToAdd = _swfClipsArr[2];
        gotoAndStop(4);
        break;
    }

    Window_content.removeChildAt(Window_content.numChildren - 1);
    Window_content.addChild(_swfToAdd);
}

非常感谢您提供的任何帮助。

编辑: 所有代码

import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.IEventDispatcher;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.events.MouseEvent;

var _swfLoader:Loader;
var _swfRequest:URLRequest;

var _swfPathArr:Array = new Array("Subfolder/Circle.swf", "Subfolder/Subsubfolder/Square.swf", "Triangle.swf");
var _loadedSWFs:int;

var _swfClipsArr:Array = new Array();
var _swfTempClip:MovieClip;

startLoading(_swfPathArr);

function startLoading(pathArr:Array):void
{
    _swfLoader = new Loader();
    _swfRequest = new URLRequest();

    addChildAt(_swfLoader, 0);

    _loadedSWFs = 0;

    loadSWF(pathArr[0]);

}

function loadSWF(path:String):void
{
    setUpListeners(_swfLoader.contentLoaderInfo);

    _swfRequest.url = path;
    _swfLoader.load(_swfRequest);

}

function setUpListeners(dispatcher:IEventDispatcher):void
{
    dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
    dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);

}

function currentSwfProgress(event:ProgressEvent):void
{
    var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
    //swfPreloader.precentTF.text = _perc + "%";
}

function onSwfComplete(event:Event):void
{
    event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
    event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);

    _swfTempClip = event.target.content;
    _swfTempClip.customID = _loadedSWFs;

    _swfClipsArr.push(_swfTempClip);

    if(_loadedSWFs < (_swfPathArr.length - 1))
    {
        _loadedSWFs++;
        loadSWF(_swfPathArr[_loadedSWFs]);
    }
    else
    {
        _swfLoader.unloadAndStop();
        _swfLoader = null;
        onCompletePreloading();
    }

}

function onCompletePreloading():void
{
    button_Circle.addEventListener(MouseEvent.CLICK, setContent);
    button_Square.addEventListener(MouseEvent.CLICK, setContent);
    button_Triangle.addEventListener(MouseEvent.CLICK, setContent);
}

function setContent(event:MouseEvent):void
{
    var _swfToAdd:MovieClip;

    switch(event.target.name)
    {
        case "button_Circle":
        _swfToAdd = _swfClipsArr[0];
        gotoAndStop(2);
        break;

        case "button_Square":
        _swfToAdd = _swfClipsArr[1];
        gotoAndStop(3);
        break;

        case "button_Triangle":
        _swfToAdd = _swfClipsArr[2];
        gotoAndStop(4);
        break;
    }

    Window_content.removeChildAt(Window_content.numChildren - 1);
    Window_content.addChild(_swfToAdd);
    //trace(_swfToAdd.customID);
}

stop();

所以多亏Cherniv建议切换SWF的顺序并看看会发生什么,似乎问题与路径数组中的第三个元素有关。只需要一双外眼睛来查看代码,他们可能能够找到一些非常明显的原因来解决我的麻烦,哈哈。如果有人能发现它,那将非常感激。

0 个答案:

没有答案