Loaded swf doesn't appear when referencing one of its control by string

好久不见. 提交于 2020-01-06 05:25:29

问题


I have in main:

var MyLoader:Loader = new Loader();
    MyLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
    MyLoader.load(new URLRequest("MySWF.swf"));         
    MyZone.addChild(loader);

And in MySWF:

    this["aSlider"].addEventListener(SliderEvent.CHANGE,OnSliderChange);

then MySWF doesn't show up on stage whereas with

    aSlider.addEventListener(SliderEvent.CHANGE,OnSliderChange);

it does appear.

I need to use this["aSlider"] because of this

http://blog.ickydime.com/2008/07/as3-notes-automatically-declare-stage.html

as pointed by https://stackoverflow.com/users/562566/ascension-systems to my previous question.


回答1:


If you're turning off 'automatically declare instances', then you must declare the slider as a public property in your class, named the same as your stage instance. So in mySWF.as, add this after your private variable declarations:

public var slider:Slider;

The instance exists on the stage, but it must be declared before it can be used. Try to avoid the myClass['myObject'] notation as it will reduce the error checking and code completion capabilities of editors like Flash Builder and FDT.



来源:https://stackoverflow.com/questions/5617318/loaded-swf-doesnt-appear-when-referencing-one-of-its-control-by-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!