Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have solved the problem.</p> <p>shortly, the solving code is below.</p> <pre><code>var earth_text:MovieClip = this.parent.getChildByName("earth_text") as MovieClip; earth_text.visible = false; </code></pre> <p>However, the this problem without knowing fully the as3.0 DisplayObject inheritance structure is a difficult problem to solve. First, a thorough understanding of the figure below should be.</p> <p><img src="https://i.stack.imgur.com/zvD5D.jpg" alt="enter image description here"></p> <p><code>this.parent</code> is Stage.</p> <p><code>this.parent.getChildByName("earth_text")</code> is DisplayObject. (take a closer look at the documentation for getChildByNames method please.)</p> <p>but type casting MovieClip. As you will see a document, this method is the actual return value of the DisplayObject. So you should be type casting.</p> <p>(if DisplayObject must be added to the stage. the code below do your work better.)</p> <pre><code>public function earth() { if(!stage) addEventListener(Event.ADDED_TO_STAGE, init); else init(); } private function init(e:Event=null):void { removeEventListener(Event.ADDED_TO_STAGE, init); var earth_text:MovieClip = this.parent.getChildByName("earth_text") as MovieClip; earth_text.visible = false; buttonMode = true; addEventListener(MouseEvent.MOUSE_DOWN, down); } </code></pre> <p>however, your all instance MovieClip in Stage. child index is very important. All DisplayObject, because they are conducted in the following order.</p> <pre><code>Stage Load -&gt; Your instance of MovieClip are added sequentially in the order index. </code></pre> <p>So the following code was written and checked the console window.</p> <p>Earth.as</p> <pre><code>var _parent:MovieClip = this.parent as MovieClip; for(var i:int = 0; i&lt;_parent.numChildren; i++) { trace("index: " + i + " object: " + _parent.getChildAt(i)); } </code></pre> <p>Your original file is an index of the earth instance was 1. So if you run the above code does not find the object. the reason is check the below console, 'll Be able to understand. instance of Earth object is added, but the remaining objects are not loaded yet. So you must to rearrange the order of the object. Look at the bottom of the console of the modified file.</p> <p>Original Files.</p> <pre><code>index: 0 object: [object Shape] index: 1 object: [object earth] index: 2 object: null index: 3 object: null index: 4 object: null index: 5 object: null index: 6 object: null index: 7 object: null index: 8 object: null index: 9 object: null index: 10 object: null index: 11 object: null index: 12 object: null index: 13 object: null index: 14 object: null index: 15 object: null index: 16 object: null index: 17 object: null </code></pre> <hr> <p><strong><code>how to rearrange instance of MovieClip object?</code></strong></p> <ol> <li>click instance of earth object in stage.</li> <li>crtl+x</li> <li>crtl+shift+v(Paste the in its same place)</li> </ol> <p>p.s: Likewise the remaining objects should have a higher index than earth_text instance. (In the console, index 16 is a earth_text instance.)</p> <p>The modified file.</p> <pre><code>index: 0 object: [object Shape] index: 1 object: [object MovieClip] index: 2 object: [object MovieClip] index: 3 object: [object MovieClip] index: 4 object: [object MovieClip] index: 5 object: [object MovieClip] index: 6 object: [object MovieClip] index: 7 object: [object MovieClip] index: 8 object: [object MovieClip] index: 9 object: [object venus] index: 10 object: [object mercury] index: 11 object: [object jupiter] index: 12 object: [object mars] index: 13 object: [object uranus] index: 14 object: [object saturn] index: 15 object: [object neptune] index: 16 object: [object MovieClip] index: 17 object: [object earth] </code></pre> <p>instance DisplayObject must always be careful when using. are added in ascending order of index at parent.</p> <p><strong>Please comment if you still do not understand. I'll be glad to help. Good Luck</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload