Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving a separate object when a button is pressed 2

Status
Not open for further replies.

TaiChi56

Technical User
Mar 6, 2002
188
US
I am working on a box that I want to open when the user clicks on a button. I drew two rectangles and have them touching each other to form a box. I made each one a separate movie clip (topbox,bottom box). I want the top box to move up to y coordinate of 26.4 and the bottom box to move to y coordinate of 288.4 when the user clicks on the button. I wrote the following code.

on (release){
mc.topbox_y=26.4
mc.bottombox_y=288.4
{

Of course nothing happens. I do not even get error codes. What am I doing wrong? Do I need to use onClipevent or something else. Please help. The secret in education lies in respecting the student. {Ralph Waldo Emerson}.
 
A couple of things. It should look like this:

Code:
on (release){
 mc.topbox._y=26.4
 mc.bottombox._y=288.4
}

- you need to seperate the _y propery from the instance name with a period
- your closing brace was backwards frozenpeas
 
Another couple of things...

What's this mc.topbox?

To target a movie clip, you have to give an instance name. It can't just have a Library name. When you drag a copy of a movie clip from the Library on stage, you have to give it a specific instance name so that you can target it. So assuming you gave them the instance name of topbox1 & bottombox1, your script would then look like this:

on (release){
_root.topbox1._y = 26.4;
_root.bottombox1._y = 288.4;
}

Regards,

oldman3.gif
 
I think that mc.topbox is correct syntax with FlashMX. In Flash 5 which is what I am most familiar with, you are correct, you would use _root.topbox._y.
 
Thank you FrozenPeas, it worked great. Now, what would I do to have it open smoothly instead of jumping straight to those coordinates? The secret in education lies in respecting the student. {Ralph Waldo Emerson}.
 
Must be using 5 then... 'Cause mc.topbox._y = 200; doesn't do anything in my MX! Regards,

oldman3.gif
 
You need to have the _x and _y move a little each frame, until it reaches the final _x and _y.

For example:
Code:
onClipEvent (load) {
   //change the start _x and _y to the coordinates you need.
   startX = 50;
   staryY = 50;
   this._x = startX;
   this._y = startY;
   speed = 5; //this is how many pixels it will move each frame.
}

onClipEvent (enterFrame) {
   this._x += speed;
   if (this._x >= 100) {  //this is the coordinate's end point, change it as needed.
      this._x = 100;
   }
   if (this._y <= 100) {
      this._y = 100;
   }
}

Of course this is just an example. Your numbers will be different, but the concept is the same.
 
Thank you for the prompt reply. This is a very nice forum and you have helped a lot. Thank you. The secret in education lies in respecting the student. {Ralph Waldo Emerson}.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top