我如何将变量从一个函数传递给另一个函数

时间:2014-06-13 12:03:12

标签: xml actionscript-3

如何将变量从一个函数传递到另一个函数,所以我创建变量来创建大量的动画片段(mc)? mc有一些属性。现在我创建了mc之后,我想将这个mc及其属性传递给另一个函数,我将通过addeventlistener转到另一个函数来继续我的代码。我希望我解释得很好。

package  {
    import flash.display.MovieClip;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.xml.XMLNode;
    import flash.events.MouseEvent;

    public class copy extends MovieClip {
        public var txml:XML;
        public var xmlloader:URLLoader= new URLLoader();
        public function copy() { 
            xmlloader.load(new URLRequest("‫‫olwantree.xml"));
            xmlloader.addEventListener(Event.COMPLETE,loaded);
        }

        public var attributes:XMLList;
        public function loaded(e:Event):void {      
            txml = new XML(xmlloader.data);
            attributes = txml.descendants();
            for (var i:uint = 0; i < attributes.length(); i++) {
                var name:String = attributes[i].@name;
                var id:String = attributes[i].@id;
                var status:String = attributes[i].@status;
                var child:int = attributes[i].@child;
                addmc(name, id, status, child);

            }
       }     

       public function addmc(name, id,status, child):void {
           var mc:Array = new Array();
           var dead:Dead = new Dead();
           var baby:Baby = new Baby();
           var txtf:TextField = new TextField();
           var txtformat:TextFormat = new TextFormat();
           mc[id] = new MovieClip();
           mc[id].name = id;
           mc[id].child = child;
           mc[id].status = status;
           mc[id].graphics.beginFill(0x000000);
           mc[id].graphics.drawRect(0, 0, 101, 101);
           mc[id].graphics.endFill();

           if (id == "1") {
               mc[id].visible = true;
           } else {
               mc[id].visible = false;
           }
           // ; // wt?!

           addChild(mc[id]);
           mc[id].x = mc[id].y = 0;
           txtformat.align = "right";
           txtf.defaultTextFormat = txtformat;
           mc[id].addChild(txtf);
           txtf.text=name ;

           if (child == " ") {
           } else {
               mc[id].addChild(baby);
               mc[id].buttonMode = true;
           }

           if (status=="d") {
               mc[id].addChild(dead)}
               mc[id].addEventListener(MouseEvent.CLICK, traceme);
           }

           public function traceme(e:MouseEvent):void {
             //here is the wrong
           }
       }
  }

我只在mc内显示第一个节点。当我点击此信号mc时,我想显示另一个mc。我想从loaded和addmc函数中获取all变量,以便在traceme函数中重用它。

0 个答案:

没有答案