I found this actionscript online to rotate a sprite around its center point but I get two errors when I use it. 1084: Syntax error: expecting identifier before leftparen. 1084: Syntax error: expecting rightparen before leftbrace. Also, in place of angleDegrees do I put in the angle I want the sprite to rotate by?
var point:Point=new Point(spr_box.x+spr_box.width/2, spr_box.y+spr_box.height/2); rotateAroundCenter(spr_box,45); function rotateAroundCenter (ob:*, angleDegrees) { var m:Matrix=ob.transform.matrix; m.tx -= point.x;
I have a movieclip and when I do 3D rotation from Transform panel, It rotates perfect, center is in the middle of image, and when I apply mc.rotationY, rotation center is in left of the image, aren't 3D rotation from Transform panel and mc.rotationY from AS same? what's up?
As you can see in my code, I'm trying to adjust on the fly the x and y properties so that the movieclip gives the impression to rotate from its center and not from its corner at 0,0
Code: var myclip:MovieClip = new MovieClip(); myclip.buttonMode = true; myclip.graphics.beginFill(0);
[code]....
but it doesn't work and the clip does not rotate well
I am trying to rotate a Sprite in three dimensions around its centerpoint, and I am struggling to understand some of the behavior of matrix3D.
Ive overridden the set rotationX, rotationY, and rotationZ methods of the Sprite as follows:
override public function set rotationX (_rotationX:Number) : void { this.transform.matrix3D.prependTranslation(this.width/2.0, this.height/2.0, 0); this.transform.matrix3D.prependRotation(-this.rotationX, Vector3D.X_AXIS);
[Code].....
I am using prependTranslation to correct the centerpoint of the rotation, and the first prependRotation to cancel out any previously-applied rotation.
Testing it out, rotationX works exactly as expected, and the Sprite rotates around its horizontal axis.
rotationY and rotationZ also appear to work fine. However, there is one problem: whenever rotationY or rotationZ are set, all of the other rotation values change as well. This is not a problem with rotationX -- if I set rotationX, nothing else changes. But if I set rotationY or rotationZ all the rotation values change, which is a problem for my app (which is trying to save and restore values).
I think I am just lacking some understanding about what is going on with matrix3D. How can I implement this so there is no interdependence between the values?
I want to change the centre of rotation of the body to be more in the front of the body. So that applyForce and also collisions make the body not turn in the centre but more in the front.
I coded an entire file based on the top left registration point of my movie clip. I want it rotate it to point at the cursor, but since the registration point isn't in the middle.. its not a perfect rotation around the center of the mc. Is there anyway to rotate it around the center of the movie clip without changing the registration point?
ActionScript Code: stage.addEventListener(Event.ENTER_FRAME, aimBall, false, 0, true); function aimBall(event:Event):void { ball_mc.rotation = getAngle(ball_mc.x, ball_mc.y, mouseX, mouseY) -90; trace(ball_mc.rotation); } function getAngle(x1:Number, y1:Number, x2:Number, y2:Number):Number { var radians:Number = Math.atan2(y1-y2, x1-x2); return rad2deg(radians); } function rad2deg(rad:Number):Number { return rad * (180/Math.PI); }
url...I'm using this code i made some changes like changing the array for a xml.In some part i put a button to stop the movement and i used [code] and it works perfectly, but then i want to return with another button to the movement. and i can't make it work.
Is it possible that I can have a fixed 3d rotation center for a movieclip.So if I have two movieclips spaced apart and I have rotated them, they rotate in their own axis rather than based on a single axis.
var shape1:Shape; shape1=draw(); addChild(shape1); shape1.rotation=50;
[Code]....
Then I want to rotate the shape at it's center point(200,202) by using shape1.rotation=50,but I find the shape don't rotate at the the center of it's shape. How to realize the function which make shape rotate at its center point?
I'm attempting to write a racing game. I've loaded in my image, I brought it to the stage and now, all I want to do is rotate it from its' center and not upper left corner.
The code:
racer.rotation += 5;
rotates from the upper left corner. How do I rotate from the center of the car/sprite? I've tried putting it into a container but I'm unsure on the coordinates of the container because I tried to set the x,y coordinates to half the sprite image but y'know, it's not doing what I expect it to.
ActionScript Code: if (arrowLeft) { var container:Sprite = new Sprite();
[Code]....
I will never sneer at another racing game! I didn't think it would be this hard to do a simple rotate of an image!
I'm trying to convert a Sprite that I have into BitmapData so I can perform some collision detection. There are a few things about the way the Sprites are used that is making this more difficult than I expected:
The Sprite itself is a container which holds another Sprite that actually has a box drawn in it. The inner Sprite is positioned negative half its width & height so that it can be rotated from the center via the container. The container may be rotated at any angle at any given time
So my approach thus far has been attempting to draw the outer Sprite onto a new BitmapData object with a Matrix to account for the difference. Whilst I can use a Matrix to make this work for one particular rotation angle, I cannot find a way to make it work for any rotation.
Here's what I'm doing to draw onto the new BitmapData:
var p:Product = getProduct(); // Product is the container with the inner sprite var bounds:Rectangle = p.getBounds(stage); var bd:BitmapData = new BitmapData(bounds.width, bounds.height, true, 0x00FFFFFF);
[Code]....
Translating by the same amount as the previous example will no longer work here, and the box will still be cut off. I've looked around at some solutions posted before or suggestions from other people but they don't seem to work for me due to my container Sprite and rotation.
I searched online and found this script that is supposed to rotate and image but I'm not sure how to use, where to put in the degree angle that I want my sprites to rotate by. Also, I get an error. 1084: Syntax error: expecting identifier before leftparen. 1084: Syntax error: expecting rightparen before leftbrace.
var point:Point=new Point(spr_box.x+spr_box.width/2, spr_box.y+spr_box.height/2); rotateAroundCenter(spr_box,45); function rotateAroundCenter (ob:*, angleDegrees) {
I am trying to place leaves in a circle to create a flower with code. I run into some problems.Is it possible to rotate the leaves so they all rotate in the direction of the center of the flower? And is it possible to calculate how many leaves can fit around a certain circle radius without to much overlapping?
Does anyone know if AS3 or FP9/10 enforces a minimum increment or resolution for the Sprite rotation property?It seems to only allow rotations in multiples of 0.25 degrees.For example:
var lines:Array = new Array(); for (i=0; i<2000; i++){ lines[i] = new Shape(); lines[i].graphics.lineStyle(.1, 0x000000);
[code]...
This draws the lines in groups at 0.25 degree spacing with gaps between them.
I've checked this behaviour: If I define a sprite (by programming) as: var square:Sprite = new Sprite(); square.graphics.beginFill(16750899, 1); square.graphics.drawRect(0, 0, width, height); square.graphics.endFill(); return square; When I check the position of the sprite ( square.x, square.y), they reference the TOP-LEFT CORNER.
If I create a symbol by Flash CS4 and export to Actionscript (I also associate one class which extends Sprite for doing "new()" in my code): var square: MyClassExtendsSprite = new MyClassExtendsSprite(); When I check the position of the sprite (x, y), they reference the CENTRE of the sprite!
I'm trying to do some augmented reality projects with flartoolkit . I can now put simple 3d objects on my marker and it works fine , but I wanna give my project some events that the user can interact with. I'm trying to trace the rotation of the marker. there's a container:DisplayObject3D which my application uses to add the 3d objects , I traced this :"trace(container.rotationZ)" but it's just returning 0 . I studied another AR application's source code and it was using the rotation of it's container object without problem .and I think I should mention that I'm using the exercise file of seb lee delisle papervision3d course from [URL]. anyone has any experience with flartoolkit? the main functions of my my code is as below:
Is it possible to have the child movieclip rotate separate of the rotation properties assigned to the parent? so ultimately giving the child element it's own axis?I've customized Lee Brimelows (gotoandlearn.com) 3D carousel to spin on the x axis to make it a vertical carousel. I've also rotated that by 45 degrees on the y axis to see all the items, and wrote a snippet of code to hide the left portion of the carousel. The entire carousel is contained within the 'container' movieclip, and inside of that are my carousel items (as seen below), with the larger item being the item in focus.
On rollover of the item in focus, I want to rotate it so it faces the viewer (as seen below),basically removing the 45 degree rotation applied to the container.The problem i'm running into is when you rotate the container (changing the rotationX of the container), the axis basically rotates with it, so when i rollover the next item 'in focus', the following happens..(in the example where it appears how it want it to, the carousel is at a rotationX of 0, so it works fine)
Program A has a cannon that aims to line up with where-ever the mouse is pointing, in 360 degrees, and fires when the mouse is is clicked. Program B has an eye instead of a cannon that should in theory do similar functions when the capslock key is toggled, but instead only has a 90 degree range of motion from the Right of the eye toward the bottom (quadrant 4 only). Where did the ther 270 degrees of rotation disappear to?
i.m trying to create a 3d rotation much like the widely used carousel only the rotation i desire consist of four upright(90 degrees) movieclips resting on a slanted, 30 degree plane which rotate onEnterFrame or following a tween on a oval like path - then pause for a given number of seconds at the four movieclips positions equal in distance on the plane
function around() { this._x = Math.cos(this.angle) * radiusX + centerX; this._y = Math.sin(this.angle) * radiusY + centerY; var s = this._y /(centerY+radiusY);
I have a center window and a background in my flash file. I am trying to get the center window to stay in the center of the web browser screen and get the background to expand and fill the entire web browser screen below center window layer. Sort of like this site [URL] I've currently converted the background to a movie clip and have this code.
My flash movie is 1440x900 but the area where all the important stuff happens in within 1024x768, i am trying to keep the middle in the center regardless of browers size or aspect ratio.
I can center the page but it doesn't work as i need it to. If the browers is small (1024x768) the swf is justified against the left edge, but not keeping the middle in the middle of the brower.
[URL] is an example of exactly what i am trying to achieve.
I am watching the tutorial on the motion editor and when he opens the motion editor to edit the Rotation X and Rotation Y values I'm in trouble.My motion editor now only shows Rotation Z but, no Rotation X or Rotation Y. What am I doing wrong?
I created a class, extended the sprite class, and now in the constructor I am trying to set the Sprite's width and height properties which are inherited from the DisplayObject. However, after I set this.width and this.height, and print the values, I get 0 for both.
What the heck is going on? When I view the livedocs I see that DisplayObject has width and height listed as public properties. I have been able to instantiate a Sprite directly, and set the width and height after it's been instantiated, so I don't get it.
package { import flash.display.*; public class ScrollBar extends Sprite {[code].....