1

我需要获取要加载到另一部电影中的标志的宽度和高度,以便将其放置在正确的位置。为什么我的 getBounds 没有获取标志的尺寸?

function displayFlags(evt:Event = null)
{
    if(!Lang) { return; }
    for (var i:uint = 0; i < Lang.length; i++)
   {
       //Language = new MovieClip();
       //Language.name = Lang[i];
       LangButton = new button01();
       LangButton.name = Lang[i];
       LangButton.btext.text = Lang[i];
       LangButton.y = LangButton.height * i;
       addChild(LangButton);

       var flag:Loader = new Loader();
       flag.load(new URLRequest(LangPath[i]+"/flag.png"));

       /// Loads Flag into Button          
       LangButton.addChild(flag);

       var fh = flag.getBounds(flag);
       trace("FLAG HEIGHT = " + fh.height); // ZERO ZERO ZERO ZERO

       // I really need this info to place the flag in the right location. 
       flag.y = (LangButton.height/2) - (flag.height/2);     
   }
evt.target.visible = false;
}

更新:2013 年 5 月 19 日

我能够弄清楚我需要等待加载标志。现在我可以得到正确的边界.. 但是,现在我无法让加载完成中的movieClip“标志”做出响应。我不认为它看到了标志的价值。

以下是我的更新代码:

function displayFlags(evt:Event = null)
{
    if(!Lang) { return; }
    for (var i:uint = 0; i < Lang.length; i++)
   {
       //Language = new MovieClip();
       //Language.name = Lang[i];
       LangButton = new button01();
       LangButton.name = Lang[i];
       LangButton.btext.text = Lang[i];
       LangButton.y = LangButton.height * i;
       addChild(LangButton);
       flag = new Loader();
       flag.load(new URLRequest(LangPath[i]+"/flag.png"));
       flag.name = Lang[i];
       flag.contentLoaderInfo.addEventListener(Event.COMPLETE, loadedFlag(flag));
       function loadedFlag()
       {
           return function()
           {
            var fh = flag.getBounds(flag);

           trace("FLAG HEIGHT = " + fh);
           trace("flag Name: "+ flag.name);

           flag.alpha = .3; 
           }
       } 
       LangButton.addChild(flag);
   }
evt.target.visible = false;
}
4

1 回答 1

1

尝试这个 :

flag.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);

然后添加功能:

function completeHandler(e:Event):void
{
    var myFlagInfo:LoaderInfo = e.currentTarget as LoaderInfo;
    var myFlag:Loader = myFlagInfo.loader;
    var fh = myFlag.getBounds(myFlag);
}
于 2013-05-19T09:53:13.730 回答