A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: reset movie clip x-position & y-position back to original

  1. #1
    Senior Member
    Join Date
    Jul 2001
    Posts
    198

    reset movie clip x-position & y-position back to original

    Is there a command to reset x-position, y-position and rotation all at once...like reset command?...or would I have to find the original x-positions and y-positions to all elements and hardcode that back....EEEK!!

    Many Thanks
    Andrea

  2. #2
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    No, there's no build-in reset that I know of. You could do something like this:

    code:

    function storeState(target) {
    for (var n in target) {
    target[n].originalX = target[n]._x;
    target[n].originalY = target[n]._y;
    target[n].originalRot = target[n]._rotation;
    }
    }

    function reset(target) {
    for (var n in target) {
    target[n]._x = target[n].originalX;
    target[n]._y = target[n].originalY;
    target[n]._rotation = target[n].originalRot;
    }
    }


    So, at the start, type storeState(_root); to save all positions of all the clips in the _root. Then you can restore the positions later using reset(_root);. I just typed the code here directly, so there could be some errors, but you get the idea.

  3. #3
    Senior Member
    Join Date
    Nov 2003
    Location
    Nevada
    Posts
    138
    hi,
    in order to create and store properties to a MovieClip instance you have to create a new class and register it to that instance.
    code:
    Object.registerClass("box", StoreState);

    //storestate constructor
    function StoreState(originalX, originalY, originalRot) {
    this.originalX = originalX;
    this.originalY = originalY;
    this.originalRot = originalRot;
    }
    //method to store vars
    StoreState.prototype.storIt = function() {
    this.originalX = this._x;
    this.originalY = this._y;
    this.originalRot = this._rotation;
    };
    //method to reset vars
    StoreState.prototype.resetIt = function() {
    this._x = this.originalX;
    this._y = this.originalY;
    this._rotation = this.originalRot;
    };
    //testing function
    testit = function () {
    var re=function(){
    box.resetIt();
    clearInterval(id1);
    }
    box.storIt();
    box._x = 100;
    box._y = 100;
    box._rotation = 48;
    var id1 = setInterval(re, 2000);
    };
    //export a movie from the libe for testing..
    this.attachMovie("box", "box", 10);

    testit();



    brint

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center