Hopefully below will help you:

I'm going to just explain how the origin stuff works, and how you can learn
to compensate for it, and maybe you can apply this to your work. Starting
off with an example where the visual elements of a sprite are not originated
at 0,0

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill();
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);

*the stage thinks this:*
mySprite.x = 10;
mySprite.y = 10;
mySprite.width = 50;
mySprite.height = 50;

*mySprite thinks this:*
this.x = 10;
this.y = 10;
this.width = 50;
this.height = 50;

But what happened to the fact that the rectangle I drew lives at x:10, y:10
!!!


*So how do you find out where the origin is from inside mySprite?*
 - mySprite.getBounds(mySprite);

this will return the boundaries of mySprite, in relation to mySprite. The
visual reality of mySprite is that its boundaries are this:

x: 10
y: 10
width:50
height:50


your origin offset is x:10, y:10. This still doesn't account for the x and y
placement of mySprite on the stage, but that is simple to calculate.


*The next part, is compensating for the scale:
**
*If you take our mySprite from above, and scale it to 2, there are some
notable changes:
 - mySprite.scaleX = mySprite.scaleY = 2;

mySprite thinks:
x:10
y:10
width:100
height:100

mySprite.getBounds(mySprite) returns this:
x:10
y:10
width:50
height:50

The visual elements inside of mySprite did not grow, but mySprite is telling
it to grow (because of the scaleX &| scaleY changes)

But what is probably messing you up is that when you scale an object that
has an origin offset, the distance between the origin offset is multiplied
by the same scale.

*Here's the example:* (same mySprite as above, and already scaleX and scaleY
= 2)

mySprite is located at x:10, y:10
mySprite is scaled to 2, with an origin offset of x:10,. y:10.
multiply the origin offsets by the scale of the object and you get x:20,
y:20

the visual position of mySprite is at x:30, y:30

We can verify this by using getBounds again, but in relation to the stage.
mySprite.getBounds(stage);

returns:
x:30
y:30
width:100
height:100



So, an example to compensate for the offset and scale would go like this:
(if you want mySprite to *look* like its at 0,0 on the stage)

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;


Now, mySprite will appear to be at 0,0 on the stage, even though the origin
is offset and the scale has been changed.


*Solutions*

You can try compensation for both the origin and scale, or you can change
the way you scale, say by scaling the actual sin wave and not the containing
parent. You could also just redraw the wave instead of changing the scale.


Hope that helps.


the end code I used:

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill(0);
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);
mySprite.scaleX = mySprite.scaleY = 2;

var props:Rectangle = new Rectangle(mySprite.x, mySprite.y, mySprite.width,
mySprite.height);
trace("mySprite x,y,width,height: " + props);
trace("mySprite.getBounds(mySprite) = " + mySprite.getBounds(mySprite));
trace("mySprite.getBounds(stage) = " + mySprite.getBounds(stage));

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;



On Tue, Aug 2, 2011 at 1:03 AM, nasim hhhhh <iranebah...@yahoo.com> wrote:

> Hi
>
> Could u help me .  i draw wave( by code) inside empy movieClip that se
> regpoint (manualy)  at middle of that when i scale it t it’s good but
> when i move align x or y It scaled by pevios position  . I want to change
> reg point and refrence point
> too , like when i do it manualy , the refrence point means (0,0) point ,
>  how do i change that point plese help me
> what is diferent between reg point and origion point (cordinate system
> (0,0)) And how to change them ?????
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



-- 
Ktu;

The information contained in this message may or may not be privileged
and/or confidential. If you are NOT the intended recipient, congratulations,
you got mail!
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to