Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I rotate an object 45 degrees at a time

New Here ,
Dec 19, 2006 Dec 19, 2006
I'm designing a simple online floor plan staging area and need to be able to move and rotate (45 degrees at a time) simple boxes. Literally picture squares on a white background that you can move around and with the click of a button (perhaps by clicking a small icon within each square) each square can be rotated at 45 degree increments clockwise.

At the same time, I need the option to duplicate a box on the stage as many times as needed. (Is that even possible?) Basically, the stage will start off with just 4 boxes, all different sizes. From each of those boxes, perhaps simply clicking on an icon of one of the boxes, a copy can be generated for placement within the stage. You get the idea.

I already have the code down for movement within the stage area....

on (press) {
startDrag(this, true);
}
on (release) {
stopDrag();
}

.... but need help with the rest. The way I have my objects (boxes) set up is with each box as a button. The buttons are then placed within a movie clip. The code above is attached to the movie clip.

Hope I'm explaining everything correctly. Any help is greatly appreciated!
TOPICS
ActionScript
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2006 Dec 19, 2006
you can use the _rotation property of movieclips to rotate a movieclip. and you can use the duplicateMovieClip() method to duplicate a movieclip (as many times as you wish).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2006 Dec 19, 2006
Update: I modified my Drag code with a Duplicate function and it works to a point (only for the Duplicate and Drag functions, not the Rtate function.) Where it falls short is the ability to duplicate multiple times. Any ideas on how to edit the following to allow infinite duplicate copies of a single MC?...

on (press) {
var name = name+1;
duplicateMovieClip (_root.caseA, "(name)", 500);
startDrag ("(name)");
}
on (release) {
stopDrag ();
}

...and again, still need help with the Rotate function.

Thanks!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 19, 2006 Dec 19, 2006
kglad,

Thanks for your reply. I'm sure you've heard this before but can you elaborate? See my most recent post for an update to my code. Can I persuade you to edit my code so I can see exactly how this is done? Admittedly I'm a total beginner when it comes to ActionScript.

Thanks a ton for your time!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 19, 2006 Dec 19, 2006
use different depths for your duplicate movieclip. and it's _rotation that you want to use, NOT Rotate.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2006 Dec 20, 2006
kglad, Thanks for your time, I really appreciate it!

My apologies for the typo ("Rotate" versus "Rotation"). Again I am a beginner with ActionScript which is why I'm here asking for help. I've spent over 2 hours today playing with depth functions (if I am not using proper terminology here please forgive me - I assume you know what I'm trying to say) and am getting nowhere fast. PLEASE, PLEASE can you (or anyone else for that matter) treat me like the novice that I am and show me where in my code I am going wrong so I can see how this is supposed to work? Simply saying "use different depths for your duplicate movieclip..." doesn't help me physically write the proper script. Believe me I will learn far more, and without the total waste of time running around in circles, by seeing how it is supposed to work.

Thanks again for your time!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 20, 2006 Dec 20, 2006
Since you asked for it...
The function that you want is the movieClip.getNextHighestDepth method. If you pass it in as the depth parameter in your duplicateMovieClip call, it will appear as the "highest" movie clip. If you need to specify the depth for some reason, check whether or not there is something already using that depth with the movieclip.getInstanceAtDepth method; if that depth is used, you can use the movieclip.swapDepths method to swap the depths of the two clips.

For your application, start with
duplicateMovieClip (_root.caseA, "(name)", this.getNextHighestDepth());
; you should be able to modify it as needed from there. Keep in mind that the duplicated movie clip will appear above all others.

Further information is available via the Help Menu->Language Reference->ActionScript Classes->Movie Clip top help page.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 20, 2006 Dec 20, 2006
Thanks Bob! I now have it working the way intended but have another minor issue - probably very simple by comparison. I need to be able to click the little "x" within the duplicated boxes (see source file link below) to close the clips that are no longer wanted and avoid cluttering up the stage. Here is the source file so you can get a better idea of what I'm talking about. Ideally, the master box (the one from which all dupes are created) will not include the "x" or at least the "x" will not be active so if someone accidentally clicks it on the master box, the box will not close. Any ideas how to accomplish this?

Here's the source file: http://www.nu-era.com/downloads/draft.zip
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 20, 2006 Dec 20, 2006
Weeeeell, there are (of course) several ways to do what you want. So, I'm just going to give you some basic principles:
The movieClip.removeMovieClip and global removeMovieClip functions are used to remove instances of movieclips created using duplicateMovieClip(), createEmptyMovieClip(), or attachMovie() .
Further, buttons have a property button.enabled which determines whether they are clickable or not.
Alternatively, you could use createEmptyMovieClip() and attachMovie() to create instances of non-master movieClips. Just use two symbols: one with the button, and one without, and have only the one without the button able to reproduce via the methods discussed earlier.
Hopefully that's what you're after.

Luck, Bob.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 21, 2006 Dec 21, 2006
Bob, thanks for your advice - I appreciate your time and effort. However, being that I'm a complete novice with ActionScript I cannot seem to construct the code properly to get the desired results as you are suggesting. I'm actually quite shocked that I've even been able to piece together as much as I have - mostly from posts on other forums (see the link in my previous post). You on the other hand sound like a complete pro and something like this would likely be second nature for you. I often find myself explaining things to others as if they've been doing what I do just as long as I. Its not until their eyes gloss over that I realize I need to be much more specific and not so general with my guidance. This is more what I need with this, more specific guidance so I can fully understand just how what you are so generously suggesting should be constructed.

Anyhow, I would very much appreciate any further assistance you are willing to provide. It would be most appreciated if you were willing to edit my code so I can see exactly where these function go and how they are constructed - this is how I learn. That said, your time is very important so if you have none available I understand.

Thanks again Bob!
Darren
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 21, 2006 Dec 21, 2006
Okay, here's a step forward, at least.
The primary change was the addition of an if clause which detected whether or not the delete handle had been clicked.
Also, I added a square background to the delete movieclip, so as to create a larger hot spot.
The reason that it doesn't remove the master movie clip as well is because movieClip.removeMovieClip only removes instances of clips that have been created using one of three clip-duplication methods (listed prior).
As to getting rid of the "X", simply create a movie clip symbol that lacks the "X", attach all the existing code to it, and have it make duplicates of another symbol that does have the "X".
Do you still want the segmented rotation thing?

Modified draft
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 22, 2006 Dec 22, 2006
WOW!! Bob you really came through in a major way. thank you so much! This is GREAT!! Even better is that looking at the code, I think I actually get what you did - not that I could duplicate it at this point but its a start in the learning process.

As for the segmented rotation thing, if you are referring to the 45 degree snap rotation, yes. I'd love it if the icons did not rotate freely but instead snapped every 45 degrees. Any thoughts?

Thanks again Bob! You made my Christmas 🙂
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 23, 2006 Dec 23, 2006
Sorry about the lag; also sorry that I couldn't actually provide an altered .fla for this answer. However, I can pseudocode it. It's neither syntactically correct not tested, but it should get the idea across. The '%' operator indicates a modulus operation, which returns the remainder of dividing a into b. (So, 1%2=0, and 1.5%2=0.5 .) The basic idea is this: divide a circle into 8 equal segments. The dividing lines are at n*45 degrees: 0, 45, 90, 135, etc. Then, rotate the circle so that one of those segments is centered on each axis; the dividing lines are then at n*45-22.5 degrees. We then test to see if the angle is closer to vertical or diagonal by comparing it against 22.5 degrees; we extend it for the negative case by adding an absolute value operation in, which makes anything put into it positive. (abs(-1)=1; abs(1)=1).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 23, 2006 Dec 23, 2006
i think 1.5%2 should be 1.5.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 24, 2006 Dec 24, 2006
LATEST
I'm glad you're watching, man. My bad, Herr Eilers; that should have been "a%b returns the remainder of dividing b into a."
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines