1

I am trying to make sprite sheets for rotation of DisplayObjects, and it seems that the gotoAndStop() calls are not working.

Here's an example of what's going on:

function createRotationalSpriteSheet ( displayObject : DisplayObject )
{
    findMaxTileDimensions( displayObject );
    MovieClip( displayObject ).gotoAndStop( 1 ); // this call does not work.
}

function findMaxTileDimensions ( displayObject : DisplayObject )
{
    MovieClip( displayObject ).gotoAndStop( 1 ); // this call works fine
}

For the gotoAndStop call that doesn't work, the label and frame number are updated but when I try to draw the DisplayObject with BitmapData.draw, the frame is still stuck on the last frame it was told to go to in the findMaxTileDimensions function.

Is this happening because I am calling the gotoAndStop function to many times in one enter frame? Is it happening because I'm calling gotoAndStop from two different functions in the same enter frame?

Jordan
  • 1,233
  • 2
  • 12
  • 32

4 Answers4

2

A few things seem to be going on here. You're using gotoAndStop(), but that won't update the images until after everything else has happened. From the docs - http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndStop() - "Brings the playhead to the specified frame of the movie clip and stops it there. This happens after all remaining actions in the frame have finished executing." So if you want this to work, then you'll need to do it over multiple frames.

Secondly, you mention that this is to sort out rotation of DisplayObjects to draw them as BitmapData's - is there animation in the MovieClip? Or is the animation that of the MovieClip rotating. If it's the latter, then setting the rotation through code and drawing the different angles will work as you're trying to do (i.e. all in one frame)

Also check out SWFSheet by bit101: http://www.bit-101.com/blog/?s=swfsheet. It's made to take an animation and export PNG sprites for it. There might be the code there, I'm not sure. In any case, you can save your anim, then embed/load it in

divillysausages
  • 7,883
  • 3
  • 25
  • 39
  • There is no animation in the frames. I am trying to create the rotational animation off of one frame at a time. You said that it all must be on the same frame, but in the findMaxTileDimensions function the gotoAndStop call works just fine. Its only when I try to gotoAndStop in the createRotationalSpriteSheet function that it breaks. – Jordan Mar 17 '11 at 18:24
1

This sounds like it might be this known bug in AIR (assuming it only happens in AIR): https://bugbase.adobe.com/index.cfm?event=bug&id=3340012

The bug report mentions a hacktastic workaround, which I just verified does work: add your MovieClip to the stage before you run through it. You can remove it when you're done.

Alternately, you could instantiate the MovieClip twice (once to get the dimensions, then once to create the BitmapDatas), or add an empty dummy frame at the start of your MovieClip and ignore that first frame.

Sarah Northway
  • 1,029
  • 1
  • 14
  • 24
-1

Two things are happening here. The main issue is that gotoAndStop is 1-based, not 0-based. gotoAndStop(0) won't generate an error though because it is expecting an object (so it can take a label or frame number).

gotoAndStop is 1-based for legacy reasons - i.e. tied to the old way of doing things in the flash IDE.

If changing this to a 1-based system still doesn't work, you will need to you addframescript (which is 0-based) see my answer here

AS3 - gotoAndStop with immediate action

Community
  • 1
  • 1
Chris
  • 54,599
  • 30
  • 149
  • 186
  • 1
    gotoAndStop being 0 or 1 based is a non-issue, because Jordan says that the first call works. It seems like something deeper/darker is going on somewhere else in the codez – Adam Harte Mar 17 '11 at 04:12
  • Yes I am actually using 1 as the frame number, I will update the question with 1's. – Jordan Mar 17 '11 at 18:17
  • @Jordan. That's ok, the problem then lies in the way stage resources are available after a gotoAndStop method call. Please see the 2nd part of my answer, esp. the link – Chris Mar 17 '11 at 21:44
-1

As a better use case, I think it would be better to use bitmap and then cache it in some data structure: read this: http://www.8bitrocket.com/2010/3/3/Tutorial-AS3-How-to-Blit-an-animation-from-a-tile-sheet-embedded-at-compile-time/
also, maybe i'm not 100% clear on the question but why do you need to use enterframe to create a sprite sheet?


you can just rotate the bitmap then capture it as a bitmapData, or simply use a matrix transformation on the bitmap data http://www.8bitrocket.com/2010/05/01/tutorial-exploring-the-as3-bitmap-class-lesson-3-scale-from-the-center-with-a-matrix/

Saad
  • 26,316
  • 15
  • 48
  • 69
  • Thanks for the response. I am using a MovieClip and rotating using the MovieClip.rotation property. Then I use a matrix transformation like you said. The problem is that in the first function the frame cannot be changed. – Jordan Mar 17 '11 at 18:16
  • @Jordan I'm confused what are you using the frames for? animation? EDIT: also, can you make sure the object is initialized when you call the first function. – Saad Mar 17 '11 at 19:16
  • The frames each hold a state of the asset all at a rotation of 0. The purpose of both functions is to create a sprite sheet of each state at all 360 angles. The findMaxTileDimensions function is used to find out the max width and height of each state so those dimensions can be used in the sprite sheet for each tile. The createRotationalSpriteSheet function creates the actual BitmapData object that is the sprite sheet. – Jordan Mar 17 '11 at 21:51
  • so there is only 1 frame then right? frame 1 contains everything at rotation 0? or do you have multiple frames?
    – Saad Mar 17 '11 at 22:23
  • so the display object contains one graphic right? and all your trying to do is take that one graphic rotate it and cache it as a bitmap data at different rotations?
    the reason I'm confused is because the display object is an abstract class and doesn't actually have reference to frames (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html) but your casting it to movieclip which makes syntactical sense but why so why would reference a frame. are you trying to cache the object into bitmap data at diff rotation from a displayobj or put it into a MC?
    – Saad Mar 17 '11 at 22:37