0

我只是在尝试让导航栏正常工作,但遇到了一些麻烦。我有一个main.swf, 里面是加载一个circle.swf,square.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 的顺序并查看会发生什么,看来问题与路径数组中的第三个元素有关。只需要一双外部的眼睛来查看代码,他们可能会发现一些非常明显的原因导致我的麻烦,哈哈。如果有人能发现它,那将不胜感激。

4

0 回答 0