0

AS3 相当大的菜鸟。我正在尝试将 SWF 加载到另一个文件中。(主 .fla 在鼠标单击时加载外部 SWFS)

我不断收到错误:1180 调用可能未定义的属性:但是,添加子项。

我的 LoadSWF 代码是:

package {
import flash.display.*;
import flash.events.*;
import flash.net.*;



public class LoadSWF {

    private var loaderFile: Loader;
    private var swfFile: Object;
    private var sourceFile: String;
    private var fileLabel: String;
    private var canDrag: Boolean;
    private var popX: int;
    private var popY: int;




    public function LoadSWF(myFile: String, myLabel: String, myX: int = 0, myY: int = 0, myDrag: Boolean = false) {
        // constructor code
        trace("Loading SWF file:", myFile);
        sourceFile = myFile;
        fileLabel = myLabel;
        canDrag = myDrag;
        popX = myX;
        popY = myY;
        openSWF();
    }

    private function openSWF(): void {
        // initialise variables      
        loaderFile = new Loader();
        swfFile = addChild(loaderFile);
        // set initial position of the SWF popup  
        loaderFile.x = popX;
        loaderFile.y = popY;
        try {
            loaderFile.load(new URLRequest(sourceFile));
            // runs after the SWF popup has finished loading     
            loaderFile.contentLoaderInfo.addEventListener(Event.COMPLETE, SWFloaded);
        } catch (err: Error) {
            // provide some error messages to help with debugging      
            trace("Error loading requested document:", sourceFile);
            trace("Error:", err);
            sourceFile = null;
        }
    } //end openSWF

    private function SWFloaded(evt: Event): void {
        // and add the required event listeners      
        loaderFile.addEventListener(MouseEvent.MOUSE_DOWN, dragSWF);
        loaderFile.addEventListener(MouseEvent.MOUSE_UP, dropSWF);
        // use the POPUP reference to access MovieClip content    
        swfFile.content.gotoAndStop(fileLabel);
        // assigns a close function to the button inside the popup    
        swfFile.content.closeBtn.addEventListener(MouseEvent.CLICK, closeSWF);
        // remove the COMPLETE event listener as it’s no longer needed      
        loaderFile.contentLoaderInfo.removeEventListener(Event.COMPLETE, SWFloaded);
    } //end SWFLOaded   


    private function dragSWF(evt: MouseEvent): void {
        swfFile.content.startDrag();
    }
    private function dropSWF(evt: MouseEvent): void {
        swfFile.content.stopDrag();
    }
    private function closeSWF(evt: MouseEvent): void {
        // remove the required event listeners first    
        loaderFile.removeEventListener(MouseEvent.MOUSE_DOWN, dragSWF);
        loaderFile.removeEventListener(MouseEvent.MOUSE_UP, dropSWF);
        swfFile.content.closeBtn.removeEventListener(MouseEvent.CLICK, closeSWF);
        // remove the pop-up    
        loaderFile.unloadAndStop();
    }


} //end class

} //结束包

我将它调用到我的主类文件中,代码是(我省略了其余部分,猜测它是不必要的):

package {

import flash.display.MovieClip;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.utils.Dictionary;
import flash.text.TextFormat;
import flash.net.*;
import flash.events.*;
import fl.controls.*;
import flash.media.*;
import fl.events.ComponentEvent;
import fl.managers.StyleManager;
import fl.data.DataProvider;
import fl.data.SimpleCollectionItem;
import fl.managers.StyleManager;
import fl.events.ComponentEvent;
import flash.events.Event;
import flash.net.SharedObject;
import LoadSWF;

public class Main extends MovieClip {

    //Declare variables
    private var componentFmt: TextFormat;
    private var radioBtnFmt: TextFormat;
    private var playerData: Object;
    private var savedGameData: SharedObject;
    // Pop-up Variables     
    private var popupFile: LoadSWF;
    private var swfPath: String;




    public function Main() {
        // constructor code
        this.savedGameData = SharedObject.getLocal("savedPlayerData");
        this.setComponents();
        this.setPlayerData();
        //this.swfPath = "";
        //this.isHelpOpen = false;
        //this.sndPath = "musicSFX/music2.mp3";
        //this.isMuted = false;
        //this.sndTrack = new LoadSND(this.sndPath, this.canRepeat);;
        //this.muteBtn.addEventListener(MouseEvent.CLICK, this.setMute);
        swfPath = "";
        helpBtn.addEventListener(MouseEvent.CLICK, openSWF);
        //hauntedForestBtn.addEventListener(MouseEvent.CLICK, openSWF);
    }



    public function openSWF(evt: MouseEvent): void {
        // determine which button was pressed  
        var myFile: String = evt.currentTarget.name.replace("Btn", ".swf");
        myFile = (swfPath == "") ? myFile : swfPath + myFile;
        if (myFile == "help.swf") {
            // load the help SWF file - is draggable  
            swfFile = new LoadSWF(myFile, currentFrameLabel, 80, 60, true);
        } else {
            // load the selected SWF file - is not draggable        
            swfFile = new LoadSWF(myFile, currentFrameLabel);
        }
        addChild(swfFile);
    }

如果有人可以帮助我找到解决方案,我将不胜感激。

谢谢 :)

4

1 回答 1

0

addChild由 定义DisplayObjectContainer

所以要访问这个功能,你必须改变LoadSWF它,使它extends DisplayObjectContainer.

于 2014-10-27T12:56:12.530 回答