this is my code.
package core
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
public class earth extends MovieClip
{
protected var position:Point = new Point(x, y);
public function earth()
{
stage.earthText_mc.visible = false; //HAVING PROBLEM WITH THIS LINE
buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, down);
}
protected function down(event:MouseEvent):void
{
parent.addChild(this);
startDrag();
addEventListener(MouseEvent.MOUSE_UP, up);
}
protected function up(event:MouseEvent):void
{
stopDrag();
if(dropTarget)
{
if(dropTarget.parent.name == "mercury_drop")
{
x = position.x = 279.95;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "venus_drop")
{
x = position.x = 342.55;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "earth_drop")
{
x = position.x = 418.2;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "mars_drop")
{
x = position.x = 497.6;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "jupiter_drop")
{
x = position.x = 613.65;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "saturn_drop")
{
x = position.x = 738.4;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "uranus_drop")
{
x = position.x = 844.8;
y = position.y = 267.15;
}
else if(dropTarget.parent.name == "neptune_drop")
{
x = position.x = 939.65;
y = position.y = 267.15;
}
else
{
x = position.x = 517.2;
y = position.y = 35.5;
}
}
}
}
}
All I want is to make the text “EARTH” invisible when I open run the flash, using only the code.. But I can’t connect to the movie clip “earthText_mc”. This script is connected at the “earth_mc” only.. I don’t know how to call the other movie clips and make them visible or invisible as I want them to..
Have solved the problem.
shortly, the solving code is below.
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.
this.parentis Stage.this.parent.getChildByName("earth_text")is DisplayObject.(take a closer look at the documentation for getChildByNames method please.)
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.
(if DisplayObject must be added to the stage. the code below do your work better.)
however, your all instance MovieClip in Stage. child index is very important. All DisplayObject, because they are conducted in the following order.
So the following code was written and checked the console window.
Earth.as
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.
Original Files.
how to rearrange instance of MovieClip object?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.)
The modified file.
instance DisplayObject must always be careful when using. are added in ascending order of index at parent.
Please comment if you still do not understand. I’ll be glad to help. Good Luck