JSwiff
flash movies the java way
JSwiff Forum
  Search   Recent Topics     Member Listing    Back to home page 
Register / 
Login 
Create motion tween  
Forum Index -> How Do I...
Author Message
Anonymous



Hi,

How can i create a motion tween using jswiff.

I tried the following, but this doesnt seem to be working:

Code:
private static SWFDocument createDocument()
     {
         //Create a new SWF document
         SWFDocument document = new SWFDocument();
         
         //Set movie background color
         new SetBackgroundColor(new RGB((short)0, (short)255, (short)0));
         
         //Define shape
         int shapeID = 1;
         Rect shapebounds = new Rect(-10, 1330, -10, 1330);
         
         //Specify fill styles array
         FillStyleArray fillStyleArray = new FillStyleArray();
         {
         	fillStyleArray.addStyle(new FillStyle(new RGB((short)255, (short)0, (short)0)));
         }
         
         //Specify line styles array
         LineStyleArray lineStyleArray = new LineStyleArray();
         {
             lineStyleArray.addStyle(new LineStyle(20, new RGB((short)0, (short)0, (short)0)));
         }
         
         //Specify Shape records
         ShapeRecord[] shapes = new ShapeRecord[5];
         {
             //1
 	        StyleChangeRecord styleChangeRecord = new StyleChangeRecord();
 	        styleChangeRecord.setLineStyle(1);
 	        styleChangeRecord.setFillStyle1(1);
 	        shapes[0] = styleChangeRecord; 
 	        //2
 	        shapes[1] = new StraightEdgeRecord(1320, 0);
 	        //3
 	        shapes[2] = new StraightEdgeRecord(0, 1320);
 	        //4
 	        shapes[3] = new StraightEdgeRecord(-1320, 0);
 	        //4
 	        shapes[4] = new StraightEdgeRecord(0, -1320);
         }
         
         ShapeWithStyle shapeWithStyle = new ShapeWithStyle(fillStyleArray, lineStyleArray, shapes); 
         DefineShape defineShape = new DefineShape(shapeID, shapebounds, shapeWithStyle);
         
         //Frame 1
 	    PlaceObject2 placeObject1 = new PlaceObject2(1);
 	    placeObject1.setCharacterId(shapeID);
 	    placeObject1.setMatrix(new Matrix(500, 820));
 	    document.addTag(placeObject1);
 	    document.addTag(new ShowFrame());
 	    
         //Frame 2
         PlaceObject2 placeObject2 = new PlaceObject2(1);
         placeObject2.setCharacterId(shapeID);
         placeObject2.setMatrix(new Matrix(1018, 1107));
         document.addTag(placeObject2);
         document.addTag(new ShowFrame());
         
         //Frame 3
         PlaceObject2 placeObject3 = new PlaceObject2(1);
         placeObject3.setCharacterId(shapeID);
         placeObject3.setMatrix(new Matrix(1535,1393));
         document.addTag(placeObject3);
         document.addTag(new ShowFrame());
         
         //Frame 4
         PlaceObject2 placeObject4 = new PlaceObject2(1);
         placeObject4.setCharacterId(shapeID);
         placeObject4.setMatrix(new Matrix( 2053,  1680));
         document.addTag(placeObject4);
         document.addTag(new ShowFrame());
         
         //Frame 5
         PlaceObject2 placeObject5 = new PlaceObject2(1);
         placeObject5.setCharacterId(shapeID);
         placeObject5.setMatrix(new Matrix(2571,1967));
         document.addTag(placeObject5);
         document.addTag(new ShowFrame());
         
         //Frame 6
         PlaceObject2 placeObject6 = new PlaceObject2(1);
         placeObject6.setCharacterId(shapeID);
         placeObject6.setMatrix(new Matrix(3088, 2253));
         document.addTag(placeObject6);
         document.addTag(new ShowFrame());
         
         //Frame 7
         PlaceObject2 placeObject7 = new PlaceObject2(1);
         placeObject7.setCharacterId(shapeID);
         placeObject7.setMatrix(new Matrix(3606, 2540));
         document.addTag(placeObject7);
         document.addTag(new ShowFrame());
         
         //Frame 8
         PlaceObject2 placeObject8 = new PlaceObject2(1);
         placeObject8.setCharacterId(shapeID);
         placeObject8.setMatrix(new Matrix(4124, 2827));
         document.addTag(placeObject8);
         document.addTag(new ShowFrame());
         
         //Frame 9
         PlaceObject2 placeObject9 = new PlaceObject2(1);
         placeObject9.setCharacterId(shapeID);
         placeObject9.setMatrix(new Matrix(4641, 3113));
         document.addTag(placeObject9);
         document.addTag(new ShowFrame());
         
         //Frame 10
         PlaceObject2 placeObject10 = new PlaceObject2(1);
         placeObject10.setCharacterId(shapeID);
         placeObject10.setMatrix(new Matrix(5159, 3400));
         document.addTag(placeObject10);
         document.addTag(new ShowFrame());
         
         document.addTag(defineShape);
         return document;
     }


When I run this code, the swf file shows a red square that sits at the first locaiton i put it on...no tweening to the last position.
Can someone point out the problem to me?
Ralf



Joined: Jul 20, 2005
Messages: 127
Location: Germany
Offline

You have to set the "move" flag of your PlaceObject2 instances, starting at the second instance (placeObject2-placeObject10):
Code:
 placeObject2.setMove();
 ...
 placeObject10.setMove();
 

I'd also suggest you add the defineShape tag before the other tags, as the PlaceObject2 instances use that character.
Use the setBackgroundColor method of the Document class in order to set the background.

Here's my code:

Code:
   private static SWFDocument createDocument() {
     //Create a new SWF document
     SWFDocument document = new SWFDocument();
 
     //Set movie background color
     document.setBackgroundColor(new RGB((short) 0, (short) 255, (short) 0));
     //Define shape
     int shapeID                   = 1;
     Rect shapebounds              = new Rect(-10, 1330, -10, 1330);
     FillStyleArray fillStyleArray = new FillStyleArray();
     {
       fillStyleArray.addStyle(
         new FillStyle(new RGB((short) 255, (short) 0, (short) 0)));
     }
     LineStyleArray lineStyleArray = new LineStyleArray();
     {
       lineStyleArray.addStyle(
         new LineStyle(20, new RGB((short) 0, (short) 0, (short) 0)));
     }
     ShapeRecord[] shapes = new ShapeRecord[5];
     {
       StyleChangeRecord styleChangeRecord = new StyleChangeRecord();
       styleChangeRecord.setLineStyle(1);
       styleChangeRecord.setFillStyle1(1);
       shapes[0]   = styleChangeRecord;
       shapes[1]   = new StraightEdgeRecord(1320, 0);
       shapes[2]   = new StraightEdgeRecord(0, 1320);
       shapes[3]   = new StraightEdgeRecord(-1320, 0);
       shapes[4]   = new StraightEdgeRecord(0, -1320);
     }
     ShapeWithStyle shapeWithStyle = new ShapeWithStyle(
         fillStyleArray, lineStyleArray, shapes);
     DefineShape defineShape       = new DefineShape(
         shapeID, shapebounds, shapeWithStyle);
     document.addTag(defineShape);
     //Frame 1
     PlaceObject2 placeObject1 = new PlaceObject2(1);
     placeObject1.setCharacterId(shapeID);
     placeObject1.setMatrix(new Matrix(500, 820));
     document.addTag(placeObject1);
     document.addTag(new ShowFrame());
     //Frame 2
     PlaceObject2 placeObject2 = new PlaceObject2(1);
     placeObject2.setCharacterId(shapeID);
     placeObject2.setMove();
     placeObject2.setMatrix(new Matrix(1018, 1107));
     document.addTag(placeObject2);
     document.addTag(new ShowFrame());
     //Frame 3
     PlaceObject2 placeObject3 = new PlaceObject2(1);
     placeObject3.setCharacterId(shapeID);
     placeObject3.setMove();
     placeObject3.setMatrix(new Matrix(1535, 1393));
     document.addTag(placeObject3);
     document.addTag(new ShowFrame());
     //Frame 4
     PlaceObject2 placeObject4 = new PlaceObject2(1);
     placeObject4.setCharacterId(shapeID);
     placeObject4.setMove();
     placeObject4.setMatrix(new Matrix(2053, 1680));
     document.addTag(placeObject4);
     document.addTag(new ShowFrame());
     //Frame 5
     PlaceObject2 placeObject5 = new PlaceObject2(1);
     placeObject5.setCharacterId(shapeID);
     placeObject5.setMove();
     placeObject5.setMatrix(new Matrix(2571, 1967));
     document.addTag(placeObject5);
     document.addTag(new ShowFrame());
     //Frame 6
     PlaceObject2 placeObject6 = new PlaceObject2(1);
     placeObject6.setCharacterId(shapeID);
     placeObject6.setMove();
     placeObject6.setMatrix(new Matrix(3088, 2253));
     document.addTag(placeObject6);
     document.addTag(new ShowFrame());
     //Frame 7
     PlaceObject2 placeObject7 = new PlaceObject2(1);
     placeObject7.setCharacterId(shapeID);
     placeObject7.setMove();
     placeObject7.setMatrix(new Matrix(3606, 2540));
     document.addTag(placeObject7);
     document.addTag(new ShowFrame());
     //Frame 8
     PlaceObject2 placeObject8 = new PlaceObject2(1);
     placeObject8.setCharacterId(shapeID);
     placeObject8.setMove();
     placeObject8.setMatrix(new Matrix(4124, 2827));
     document.addTag(placeObject8);
     document.addTag(new ShowFrame());
     //Frame 9
     PlaceObject2 placeObject9 = new PlaceObject2(1);
     placeObject9.setCharacterId(shapeID);
     placeObject9.setMove();
     placeObject9.setMatrix(new Matrix(4641, 3113));
     document.addTag(placeObject9);
     document.addTag(new ShowFrame());
     //Frame 10
     PlaceObject2 placeObject10 = new PlaceObject2(1);
     placeObject10.setCharacterId(shapeID);
     placeObject10.setMove();
     placeObject10.setMatrix(new Matrix(5159, 3400));
     document.addTag(placeObject10);
     document.addTag(new ShowFrame());
     return document;
   }
 
 
  Forum Index -> How Do I...
Go to:   
Legal notes
Powered by JForum 2.1.4 © 2005 - Rafael Steil