从类AS3向舞台添加子项

时间:2014-11-06 00:36:48

标签: actionscript-3 flash

我正在尝试做一些非常基本的事情,将一个影片剪辑从图书馆添加到舞台上。我创建了一个名为link的类,它扩展了MovieClip。我在库中有两个影片剪辑,第一个最初加载的影片包含应该删除第一个影片剪辑并加载第二个影片剪辑的按钮。但是,我无法使用addChild()加载第二个。我希望有一些显而易见的东西让我失踪。我是AS3的新手。以下是链接类的代码:

package classes.GEN1P0
{
import flash.display.SimpleButton;
import flash.display.*;
import flash.events.*;
import fl.controls.*;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

    public class link extends MovieClip
        {
            public var links:Vector.<SimpleButton >  = new Vector.<SimpleButton >;
            public var sourceMap:redMC = new redMC  ;
            public var sourceMap2:blueMC = new blueMC  ;
            public var panZoomMap:PanZoomMap = new PanZoomMap(sourceMap,704,556.3);
            public var diagram:PanZoomMap = new PanZoomMap(sourceMap2,704.45,556.3);
            public var zoomControls:ZoomControls = new ZoomControls(panZoomMap);
            public var zoomControls2:ZoomControls = new ZoomControls(diagram);
            public var navWindow:NavigatorWindow = new NavigatorWindow(panZoomMap);
            public var navWindow2:NavigatorWindow = new NavigatorWindow(diagram);

    public function link()
        {
        }
    /////////////////////////////
    //Vector for Links
    /////////////////////////////
    public function linkVector():void
    {
        for (var m:int = 0; m < 2; m++)
        {
            var linkNumb:SimpleButton = RunWise_GEN_1P0_Electrical_Schematic.sourceMap.panner.schematic.link_movies.getChildAt(m);
            if ((linkNumb is SimpleButton))
            {
                links.push(linkNumb);
                var linkName:String = links[m].name;
            }
        }
        for (var n:int = 0; n<links.length; n++)
        {
            links[n].addEventListener(MouseEvent.CLICK, linkTo);
        }
        function linkTo(e:Event):void
            {

                addChild(diagram);
                diagram.x = 291.35;
                diagram.y = 22.15;

                RunWise_GEN_1P0_Electrical_Schematic.panZoomMap.parent.removeChild(RunWise_GEN_1P0_Electrical_Schematic.panZoomMap);
                switch (e.target.name)
                  {
                  case "PPOS":
                  trace ("PPOS");
                  break;
                  case "PYKPOS":
                  trace ("PYKPOS");
                  break;
                  }

            }
    }
    //End Code Here
}

}

1 个答案:

答案 0 :(得分:0)

应该像

一样简单
var _link:link = new link();
addChild(_link);

注意:通常在AS3中创建类时,使用大写字母作为类名的第一个字母

public class Link extends MovieClip