开发者

Rotate an Image Continuously

I want to rotate开发者_Go百科 an image continuously on page load. Code works fine for 1 rotation on page load but to achieve the same effect continuously I have included the .play() statement in an infinite while loop as shown below. But it causes the page to hang and nothing shows up.

while (i == 1)
{
    if (rotEff.isPlaying != true)
    {
        rotEff.play();
    }
}

Any pointers on how to achieve this effect would be of great help


Try setting the repeatCount property of your Effect object to 0 so that it repeats indefinitely:

<fx:Declarations>
    <s:Rotate id="rotate" target="{image}" angleBy="360" duration="1000" repeatCount="0" autoCenterTransform="true"></s:Rotate>
</fx:Declarations>

[UPDATE]

In response to sandy's comment:

thanks taurayi...setting repeatCount solved the issue..However there is a little bit of transition lag from one complete 360 round to another round..is it feasible to get rid of that also..?

Set the easer property to null like so:

<fx:Declarations>
    <s:Rotate id="rotate" target="{image}" angleBy="360" duration="1000" repeatCount="0" autoCenterTransform="true" easer="{null}"></s:Rotate>
</fx:Declarations>


Very simple. Just set up an enter frame listener to operate as load occurs (don't use timeline animation).

obj.addEventListener(Event.ENTER_FRAME, doRotate);

function doRotate(e:Event):void{
    obj.rotation += 1; //in whatever direction / orientation / increment you wish
}

when load is done, just remove the listener.


If this is Flex application, I would recommend you use Timer object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜