Jump to content
Search Community

Rotating/easing mc in place?

flash08 test
Moderator Tag

Recommended Posts

I'm converting some old AS2 code to AS3.

 

I had some old code that rotated a circular-shaped mc IN PLACE by different amounts, depending on which button the user clicked. Kind of like a "spinnner" effect. I plan on adding an easing function with TweenMax replacing the old code.

 

I am using for the TweenMax rotation, as a test

 

TweenMax.to(mc, 1, {rotation:120, ease:Cubic.easeIn});

 

But what this does is to rotate the mc itself around a circular path, but not in place. I even played with the interactive demo on the TweenMax page, which yielded the same code. What am I missing?

Link to comment
Share on other sites

Sounds like your registration point isn't in the center of your object. Remember, things will always rotate around the registration point - that has nothing to do with TweenLite/Max. So you can either alter your asset to make sure the registration point is where you want it to be (the center in this case) or use the transformAroundCenter or transformAroundPoint plugin which can tween things as though they have a custom registration point - see the Plugin Explorer for interactive examples of those plugins. http://www.greensock.com/tweenlite/#plugins

Link to comment
Share on other sites

Thank you - that's it, of course.

 

In creating the new symbols, somehow I completely forgot to pick the center registration point out of that tiny box in the Flash dialog. I guess I was assuming that the default registration point would be the center; I think it just defaults to whatever you picked the last time you did Convert to Symbol. One of these days I'll have to go back into the prefs and see if I can fix that...

Link to comment
Share on other sites

Now that I've got TweenMax working, I'm trying to use it to replace the old AS1 code that I'm dealing with here.

 

I've got some code written in AS1, and I need to update it for future maintenance purposes. All that's going on here is that when a user clicks on a button, it causes a graphic "spinner" to rotate around its central axis. The AS1 code won't work in a AS3 environment, as basically, you can't attach an action to a movieclip or button instance as you could long ago in AS1.

 

The old code, attached to the mc instance Mybutton:

 

on (press) {

setProperty("/Myclip", _rotation, "-20");

 

I tried:

 

import com.greensock.*;

import com.greensock.easing.*;

Mybutton.addEventListener(MouseEvent.CLICK,shifter);

function shifter(TweenMax.to(Myclip, 1, {rotation:120, ease:Cubic.easeIn});

 

No errors in compiling, nothing happens. I just HATE AS3 syntax...so much less intuitive than previous versions.

Link to comment
Share on other sites

So, what I tried was this:

 

import com.greensock.*;

import com.greensock.easing.*;

Mybutton.addEventListener(MouseEvent.CLICK,shifter);

function shifter(e:MouseEvent):void{

TweenMax.to(Myclip, 1, {rotation:120, ease:Cubic.easeIn});

}

 

No more errors in compiling - but also no rotation of Myclip. I went in and commented out all of the AS1 code on the different buttons, as well. I must still be missing something. Reading Moock's AS3 book as fast as I can...

 

Update: Started with a new file, button works OK. There must be some remnant of AS1 code I can't see in the older file.

 

But, what I can't seem to get a handle on is how to have MULTIPLE buttons, each rotating my mc by differing amounts. In AS1, all I needed to do was to attach actions to the button instances. The basic problem is that these individual buttons are physically INSIDE my rotating mc - like rotating a wheel to see what specific place it comes to rest - Wheel of Fortune style. The buttons rotate along with the rest of the wheel.

Link to comment
Share on other sites

before getting into the wheels within wheels bit, it seems you are either:

 

not targeting your MyButton properly or MyClip, this is one of those times that the AS3 compile errors would really help you out.

 

if MyButton or MyClip are in other clips, make sure you have the proper path like wheel_mc.MyClip

 

you could try adding a few traces where your existing code is:

 

trace(MyClip)

trace(MyButton)

 

to see if those objects are in the same scope as your other code.

Link to comment
Share on other sites

Thanks for your suggestions.

 

Here is what I tried:

 

The parent wheel mc is called Wheel. I can easily rotate Wheel with a button instance called Rotate with this in the timeline:

 

import com.greensock.*;

import com.greensock.easing.*;

Rotate.addEventListener(MouseEvent.CLICK,shifter);

function shifter(event:MouseEvent):void {

TweenMax.to(Wheel, 1, {rotation:120, ease:Cubic.easeIn});

}

 

But, if I edit Wheel and put Rotate inside Wheel, when I click on the button, nothing happens and the output dialog reports, "Access of undefined property Rotate" I assume because the path is not properly defined? How does AS3 want me to call the parent Wheel from it's child button Rotate?

 

I tried this:

 

import com.greensock.*;

import com.greensock.easing.*;

Rotate.addEventListener(MouseEvent.CLICK,shifter);

function shifter(event:MouseEvent):void {

TweenMax.to(Wheel, 1, {rotation:120, ease:Cubic.easeIn});

}

trace(Rotate)

trace(Wheel)

 

[object SimpleButton]

[object Wheel_2]

 

... and now when I click the button, it rotates the whole stage!!! So I'm almost there. It's obviously the reference to Wheel needing to indicate that it is a parent mc of the Rotate button.

Link to comment
Share on other sites

I don't know how Rotate can be undefined and yet the trace still works. seems odd.

if you code is on Frame 1 of main timeline and Rotate lives in Wheel.

then your code would be:

 

Wheel.rotate.addEventListener(MouseEvent.CLICK,shifter);

 

 

if in fact the problem is that Rotate can't target Wheel here are some tips on targeting various parent clips in AS3

 

http://snipplr.com/view/15833/actionscr ... timelines/

Link to comment
Share on other sites

Well, I started wuith a clean file and - your last suggestion works fine! It was the EventListener that needed to specify its target according to the parent.child relationship.

 

Wheel.rotate.addEventListener(MouseEvent.CLICK,shifter);

 

I looked around in the old file for some other conflicting AS, but found nothing.

 

Thanks so much for your help! I still don't find AS3 very intuitive compared to its antecedents...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...