开发者

referencing instance names from linked class in AS3

I've got a linked class, with an external .as file, tied to a movie clip called "Menu" in an encompassing fla. In this actionscript file, I am trying to pull some information from a few things I made with the flash authoring tool. There are a few symbols on stage in the fla that I drew with instance names "greensboro" and "birmingham", and I want to get their x-position inside some functions of the linked class. I've tried returning a value from "greensboro.x" but of course it says the variable greensboro doesn't exist, because I haven't defined it in the class. Surely there is some way of getting that info in a variable of my linked class!

Edit: here is some code to show what I've tried(cutting everything else). This is in the .as file 开发者_StackOverflow中文版of the linked class:

package {

    import flash.display.*;
    import flash.net.URLRequest;
    import flash.events.*;
    import flash.net.URLLoader;
    import fl.transitions.Tween;


    public class Menu extends MovieClip {

        public function Menu() {
        trace(birmingham.x);
        }

        public function get birmingham() : MovieClip {
        return root.getChildByName("birmingham") as MovieClip;
        }
    }
}


you can either make a public var inside the class like this:

public var birmingham : MovieClip;

and use it afterwards or create a getter like this to read out information:

public function get birmingham() : MovieClip
{
   return this.getChildByName("birmingham") as MovieClip;
}

in both cases you should be able to use birmingham.x


xValue = this['greensboro'].x;

OR

xValue = this['birmingham'].x;


Alrighty, dudes. Just figured it out...... I used BJornson's code in the linked class, but replaced this with parent. Here it is:

package {

    import flash.display.*;


    public class Menu extends MovieClip {

        public function Menu() {
        trace(birmingham.x);
        }

        public function get birmingham() : MovieClip {
        return parent.getChildByName("birmingham") as MovieClip;
        }
    }
}

Like magic! now I'm pulling x-value from MovieClip objects on the main fla's stage, and returning them for use inside my linked class! Super useful

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜