A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Changing the registration point

  1. #1
    Member
    Join Date
    Feb 2004
    Posts
    47

    Changing the registration point

    Hi

    I'm trying to change the registration point of a movieclip so that I can rotate it around that point.

    I found setTransformationPoint() but I can't get that to do anything and the code is not coloured as a function when I type it in (I have MX2004 pro) and anyway I'm not sure if that is the function I want.

    If anyone knows how to do this or a workaround please let me know

    Thanks

  2. #2
    nobody
    Join Date
    Aug 2002
    Posts
    269
    Where did you get this function ?
    kra, kra

  3. #3
    Member
    Join Date
    Feb 2004
    Posts
    47
    The function is in the Flash help.


    document.setTransformationPoint()
    Availability
    Flash MX 2004.

    Usage
    document.setTransformationPoint( transformationPoint )

    Parameters
    transformationPoint A pair of floating point numbers that specifies values for each of the following elements:

    Shapes: transformationPoint is set relative to document. 0,0 is the same as the Stage (upper left corner).
    Symbols: transformationPoint is set relative to the symbol’s registration point. 0,0 is located at the registration point.
    Text: transformationPoint is set relative to the text field. 0,0 is the upper left corner of text field.
    Bitmaps/videos: transformationPoint is set relative to bitmap/video. 0,0 is the upper left corner of the bitmap or video.
    Groups: transformationPoint is set relative to document. 0,0 is the same as the Stage (upper left corner)
    Returns
    Nothing.

    Description
    Method; moves the transformation point of the current selection. See document.getTransformationPoint().

    Example
    The following example sets the transformation point of the current selection to 100, 200:

    fl.getDocumentDOM().setTransformationPoint({x:100, y:200});

  4. #4
    nobody
    Join Date
    Aug 2002
    Posts
    269
    Thats Flash javascript. Useless for actionscript programming.
    kra, kra

  5. #5
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    i dont think that there is a way to change frame rate and interestingly you perhaps dont want to go too fast because slower pc's might not be able to handle it. this is a bit of code i came across - never tried it - do what you will with it.
    The question was exactly the same as yours.......

    no, but you can fake it. if you add the code below the dotted line to a frame in your flash file, you can use:

    mc.playF(m,n,fps); /* to play movieclip mc from frame m to frame n at fps frames per second */

    ---------------------------------------------------

    MovieClip.prototype.playF = function(m, n, fps) {
    if (!var3141592) {
    var3141592 = 0;
    playA = new Array();
    }
    this.m = m;
    this.n = n;
    this.fps = fps;
    this.gotoAndStop(this.m);
    playA[var3141592] = setInterval(playF2, 1000/this.fps, this, var3141592);
    var3141592++;
    };
    function playF2(mc, ind) {
    if (mc.m<mc.n) {
    mc.nextFrame();
    } else {
    mc.prevFrame();
    }
    if (mc._currentFrame == mc.n) {
    clearInterval(playA[ind]);
    }
    updateAfterEvent();
    }
    good luck and let me know what happens

  6. #6
    Member
    Join Date
    Feb 2004
    Posts
    47
    Err, I think you must have misread the question or posted in the wrong thread, I don't want to change the framerate and I think you can using Javascript document.frameRate anyway but I could be wrong, I've never tried it.

  7. #7
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    read it wrong
    oops
    ignore anything i ever say

  8. #8
    Senior Member
    Join Date
    Feb 2005
    Posts
    149
    Not sure if this is what you had in mind, but you can change the registration point (_x,_y)of the child clip relative to the parent clip and then rotate on the parent clip.

    This .fla shows the reg point of the parent clip as a black dot. The reg point of each child clip (red square, green square, blue square) is repositioned relative to the black dot. Rotation is performed on the parent.

  9. #9
    Member
    Join Date
    Feb 2004
    Posts
    47
    OK, I thought I'd found a workaround but it doesn't work.

    I think that example goes part way to doing what I want but I haven't fully understood it yet, I'm sure I will after a bit of a think and a cup of coffee.

    I'm trying to drag things round with inertia like This Site so things need to rotate around the point that you drag by.
    Last edited by yanyorga; 05-08-2005 at 03:08 AM.

  10. #10
    nobody
    Join Date
    Aug 2002
    Posts
    269
    Why dont you try to change a position of a clip inside a clip?
    Use relative and absolute positions of a mouse.
    kra, kra

  11. #11
    Member
    Join Date
    Feb 2004
    Posts
    47
    That works fine for the first time you drag, you just move the child one way and the parent the other.

    But once you have rotated it and released, the next time you grab, you have to start thinking about trig functions to find how much to move it by.

    I've found the code to do it by decompiling the example I posted, but damn, that's a lot of code. It must have been a college project because it has force, weight and inertia and uses proper physics. There's no way you'd put in that much effort for a client

    I guess I'll just pick through his code and try to sort it out. I'll update this thread with the code when I do, thanks for the help guys.

  12. #12
    Senior Member
    Join Date
    Feb 2005
    Posts
    149
    Hi, yanyorga

    Here's a method based on "Flash Hacks" by Sham Bhangal. I believe this is the underlying principle behind what's going on in your example site.

    The code, "flash41_turn" is here in chapter 5:

    http://examples.oreilly.com/flashhks/chapters/

    Sounds like the script for your site is complex. This one is relatively straightforward and may be "good enough".

    The .fla for a modified example which comes close to your implementation is attached. There are 3 mc's being used to calculate the position of the visible mc (the blue one). You can uncomment the other two to see the positioning relationship. Red is the topmost mc, then green, then blue. Rotation is performed on red. And then you can play with the parameters to adjust the sensitivity.

    Hope this helps.

  13. #13
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    Hi, guys. Hope this example will help you.
    Attached Files Attached Files

  14. #14
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    Ups, there is some correction in the code
    code:
    this.onMouseDown = function() {
    if (bg.hitTest(_root._xmouse, _root._ymouse, true)) {
    d = true;
    rCenter.x = _root._xmouse;
    rCenter.y = _root._ymouse;
    this._x = rCenter.x;
    this._y = rCenter.y;
    bg.globalToLocal(rCenter);
    }
    }


  15. #15
    Senior Member
    Join Date
    Feb 2005
    Posts
    149
    Hmmmm! Looks like globalToLocal() makes life much easier. sergwiz, thanks for that bit in your code. So now, attached is an updated script which is not looking so bad as a rough approximation of the referenced site.

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