this code is only show one display object on the stage !

var skeletonData:SkeletonData = json.readSkeletonData(new SpineboyJson()); 
var stateData:AnimationStateData = new AnimationStateData(skeletonData); 

stage.addEventListener(KeyboardEvent.KEY_DOWN,function(e:KeyboardEvent):void{
   var skeleton:SkeletonAnimation = new SkeletonAnimation(skeletonData, stateData);
   skeleton.state.addAnimationByName(0, "attack", true, 0);
   addChild(skeleton);
   skeleton.x = Math.random()*stage.stageWidth;
   skeleton.y = Math.random()*stage.stageHeight;
})

and this code can show Multiple display object , but is too low FPS and Memory is too big!

var by:ByteArray = new SpineboyJson() as ByteArray;
stage.addEventListener(KeyboardEvent.KEY_DOWN,function(e:KeyboardEvent):void{
   by.position = 0;
   var skeletonData:SkeletonData = json.readSkeletonData(by); 
   var stateData:AnimationStateData = new AnimationStateData(skeletonData);
   var skeleton:SkeletonAnimation = new SkeletonAnimation(skeletonData, stateData);
   skeleton.state.addAnimationByName(0, "attack", true, 0);
   addChild(skeleton);
   skeleton.x = Math.random()*stage.stageWidth;
   skeleton.y = Math.random()*stage.stageHeight;
})

tell me how to use AS3 runtime

sorry , my english is not very good

Related Discussions
...

Reuse the *Data classes, don't load them multiple times.

var by:ByteArray = new SpineboyJson() as ByteArray;
var skeletonData:SkeletonData = json.readSkeletonData(by); 
var stateData:AnimationStateData = new AnimationStateData(skeletonData);
stage.addEventListener(KeyboardEvent.KEY_DOWN,function(e:KeyboardEvent):void{
   by.position = 0;
   var skeleton:SkeletonAnimation = new SkeletonAnimation(skeletonData, stateData);
   skeleton.state.addAnimationByName(0, "attack", true, 0);
   addChild(skeleton);
   skeleton.x = Math.random()*stage.stageWidth;
   skeleton.y = Math.random()*stage.stageHeight;
});

The "Instance Data" section in the diagram below is the SkeletonAnimation instance. You can see it is separate from the data, allowing many skeleton instances to share all the same data.

Image removed due to the lack of support for HTTPS. | Show Anyway

Also see: Runtime documentation

if you do this , it will show only one display object , No matter how many times I press the keys

so , it is a bug ?

Try adding this to SpineboyExample:

addEventListener(KeyboardEvent.KEY_DOWN, function (e:KeyboardEvent):void {
   var skeleton:SkeletonAnimation = new SkeletonAnimation(skeletonData, true, stateData);
   skeleton.state.setAnimationByName(0, "run", true);
   addChild(skeleton);
   Starling.juggler.add(skeleton);
   skeleton.x = Math.random() * stage.stageWidth;
   skeleton.y = Math.random() * stage.stageHeight;
});

I tested it, it works. Be sure to update your runtimes though, I just fixed some batching problems.

that is starling runtime , not as3 runtime .
starling runtime is works normal , but as3 runtime not

you can adding this code to as3 runtime - spine-as3-example - Main.as

          // spine-as3-example - Main.as 
          ......
if (false) {
   skeleton.state.setAnimationByName(0, "test", true);
} else {
   skeleton.state.setAnimationByName(0, "walk", true);
   skeleton.state.addAnimationByName(0, "jump", false, 3);
   skeleton.state.addAnimationByName(0, "run", true, 0);
}

addChild(skeleton);

     // my test code : I want to show two instances on the satge , and they are used the same data
     //                          but after 3 second later it has only one
setTimeout(function():void{
   var skeleton2:SkeletonAnimation = new SkeletonAnimation(skeletonData, stateData);
   skeleton2.x = 700;
   skeleton2.y = 600;
   skeleton2.state.setAnimationByName(0, "run", true);
   skeleton2.state.addAnimationByName(0, "jump", false, 3);
   skeleton2.state.addAnimationByName(0, "run", true, 0);
   addChild(skeleton2);
},3000)


Aha! My apologies, I mistakenly assumed it was Starling. I've committed a fix.

I update runtimes and tested .
It could show Multiple instances , but it still low FPS and Memory is too big .

test result : 30 instances FPS=24 Memory =172,116 KB

it looks like new data every time


Hmm, thanks for sticking with me. 🙂 Please update and try again. Memory usage is reduced by 60% by caching the region BitmapData. Probably not much we can do about CPU usage.

It's not loading the skeleton data multiple times. Look in spine-as3/src/spine/SkeletonSprite.as to see what it does. Look inside the if (!wrapper) { block. The code in this block runs the first time an attachment is displayed. It gets a BitmapData instance from the RegionAttachment, which is shared data and only loaded once. Then it copies the BitmapData to a new BitmapData of the correct size. Then it creates a Bitmap and a Sprite (both DisplayObjects, ie scene graph objects). After that initial setup, the sprite is positioned, rotated, and scaled so the attachment is drawn in the correct place. The attachment sprites are stored on the skeleton (using weak keys) in case they need to be shown again later.

Using a DisplayObject per attachment like this has a number of downsides. Shear and nonuniform scaling aren't supported because the resulting image would be diamond shaped, which can't be done by setting position, rotation, scale on the sprite. Creating a Bitmap and Sprite per attachment for every skeleton isn't great, especially since they are kept around even if the attachment is hidden to avoid having to recreate them if it is shown again. Also, the children are cleared and added again every frame because the draw order might change and attachments might be hidden or new attachments shown.

Most other runtimes can draw an image using vertices and without allocation, which avoids all these problems.