Flash - rotating an image around a point

I have been working with Flash recently – when I say Flash I really mean Actionscript – it seems to me the Actionscript and Javascript are getting pretty close together as it was not that difficult to get the gist of the action script.

One of things I was doing involves rotating a dynamically loaded image. This caused me quite a few problems and I had to re-learn all my school trig stuff. Unfortunately this didn’t help very much.

Eventually I found this post that explains how to do it. I have included the code below as well:

this.createEmptyMovieClip("mc1",12);
mc1.createEmptyMovieClip("mc2",14);
mc1._visible = false; // don't want to see the repositioning happen
loadMovie('mypicture.jpg', mc1.mc2);
id = setInterval(positionClip, 400);

function positionClip() {
if(!mc1.mc2._width) // partially loaded yet?
return;
clearInterval(id);
mc1._x = 400;
mc1._y = 300;
// move the 2nd clip relative to the first
mc1.mc2._x = mc1.mc2._x - (mc1.mc2._width / 2);
mc1.mc2._y = mc1.mc2._y - (mc1.mc2._height / 2);
mc1._visible = true;
id = setInterval(spin, 12);
}

spin = function() {
mc1._rotation += 3;
updateAfterEvent();
}

Basically you create an empty ‘holder’ movieclip and then create your image movieclip within that one. Then you position the center of the image over the origin(top left hand corner) on the ‘holder’. The code above should run pretty much as is – obviously you need to put the correct path in for the image. When you publish the movie the image should slowly rotate.

This had all the ingredients to do what I needed but I could not get the width of the image when it was loaded. I was trying check the width of the image with the onLoadComplete for some reason the width kept coming out a zero. The logic seemed right and I was getting a bit annoyed. Then I thought I better do a bit a googling and see if I could find anything about this method. Low and behold I found When Complete is Not Complete which almost instantaneously sorted out the problem by using onLoadInit to trap the width.

Anyway I sorted out the rotation which works perfectly – obviously doing the rotation screwed up another part of the movie but thats another story!

Comments

Leave a Reply

Stuff I Dugg

  • 27 Adobe AIR Applications - Handy For Web Designers

    Every designer & developer loves handy tools that simplify frequent tasks. And, even if you’ve a complicated software that does the same thing, usually it is much more effective to run a tiny, fast-loading application that does the job.This is a list of 27 functional Adobe AIR applications that can help a web designer to design & develop.

  • Michael Moore on Slacker Uprising’s Piracy ‘Problem’

    Michael Moore decided to give away his latest film ‘Slacker Uprising’ for free, but only to people in the US and Canada. However, since he chose to use BitTorrent, and open trackers such as The Pirate Bay, it was fairly easy for the rest of the world to download it as well. Was this done on purpose? Moore responds.

  • Oops I voted for Rick Astley 961 times

    Wasting no time in getting their man elected "Best Act Ever," the large and mostly anonymous under-culture of Rick Astley fans has already deployed a device to defraud the voting on MTV Europe's website. The "RickVoter" is a very basic utility that simply navigates to MTV's voting page and votes for Astley...over and over and over.

  • Banksy in New Orleans

    The celebrated street artist hit up New Orleans before the anniversary of Hurricane Katrina.

  • 8 hacks to make Firefox ridiculously fast

    Firefox has been outperforming IE in every department for years, and version 3 is speedier than ever.But tweak the right settings and you could make it faster still, more than doubling your speed in some situations,

  • 10 hot Web redesigns of 2008

    it's a good chance to take a look back at some of this year's redesigns and talk about what was changed and/or fixed.

  • IEs4Linux lets you install Internet Explorer under Linux

    Because a large portion of end user machines attached to the Internet are Windows machines, Web developers have no choice but to develop Web applications that, while they don't necessarily rely on Microsoft technology, do have to work properly with Microsoft's Internet Explorer browser. That usually means developers require a Windows installation a

  • 12 year old boy invents new type of solar cell

    Now here’s a story that makes me feel profoundly unaccomplished: a 12 year old boy in Beaverton, Oregon recently developed a new type of 3D solar cell that makes other solar cells look inefficient by comparison.William Yuan’s 3D cell can absorb both visible and UV light. According to his calculations, solar panels equipped with his 3D cells..

  • 13 Amazing Firefox Add-Ons To Make Designers Lives Easier

    In this post, I am listing down 13 Amazing Firefox Add-Ons To Make Designers Lives Easier.You are welcome to share if you know more amazing firefox add-ons that will save time which our readers/viewers may like.

  • 5 Tips For Better Sleep

    With these five easy tricks, you'll have no trouble springing from the sheets rested and ready.

Subscribe

Who Am I?

No Sweat Apparel.com