[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Setting initial draggable mc location to reset at end of quiz

I'd like to be able to set the initial location of each of my draggable movieclips and then reset them to that initial location with the press of a button.

On each button, I was trying:

    _root.xpos1 = _target._x;
    _root.ypos1 = _target._y;

and then trying to reset the mc's location from a button for restarting the program like this:

    setProperty ("Button1", _x, _root.xpos1);
    setProperty ("Button1", _y, _root.ypos1);

But that doesn't work.

Thank you.
0
crazycharlie
Asked:
crazycharlie
1 Solution
 
OBCTCommented:
Try setting the co-ordinats using this code:

on (release) {          
_root.MC._x = 200;   //_root.instancename._x = your x position
_root.MC._y = 200;   //_root.instancename._y = your y position
}

Just change the instance name and the co-ordinats to suit your needs.

Cheers

-OBCT
0
 
blue-genieCommented:
here's a much better solution. You don't need to explicitly specify coordinates, let flash work it out for you.

on all the movieclips, that you wish to reset, include the following code:

onClipEvent(load) {
this.startX = this._x;
this.startY = this._y;
}

this will set variables with the starting x and y position for each movieclip.
then on the reset button.

if you've named your movieclips nicely, ie item1, item 2, item3 for example, then you can use a for loop

on (press) {
for (i=1; i<4; i++) {
_root["item" add i]._x = _root["item" add i].startX;
_root["item" add i]._y = _root["item" add i].startY;
}
}

otherwise you'll need to call each instance of the movieclip explicitly. (not most efficient, but it works)

on (press) {
mcName._x = mcName.startX;
mcName._y = mcName.startY;
}


0
 
crazycharlieAuthor Commented:
blue-genie,

That's exactly what I was looking for.  I think I was setting my variables correctly before, but just not calling them correctly.  It's working now!

You're a life-saver.

Ch@rlie
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now