topical media & game development

talk show tell print

actionscript-book-SpriteArranger-SpriteArranger.mx

actionscript-book-SpriteArranger-SpriteArranger.mx [swf] [flash] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
      xmlns:example="*"
      xmlns="*" 
      paddingTop="0"
      width="100%" 
      height="100%"
      layout="vertical"
      creationComplete="initApp()">
      
      <mx:Script>
          <![CDATA[
              //import com.example.programmingas3.geometricshapes.IGeometricShape;
              //import com.example.programmingas3.geometricshapes.GeometricShapeFactory;
              //import com.example.programmingas3.geometricshapes.RegularPolygon;
              //import com.example.programmingas3.spritearranger.GeometricSprite;
              //import com.example.programmingas3.geometricshapes.Circle;
              
              import flash.display.Shape;
              
              public function initApp():void
              {
                  canvas.initCanvas(0xFFFFFF, 0xCCCCCC);
              }
              
              public function addShape():void
              {
                  var shapeName:String = shapeNameCbo.selectedLabel;
                  this.canvas.addShape(shapeName, shapeSizeNs.value);
                  
                  describeShapes();
              }
              
              public function describeShapes():void
              {
                  if (actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite != null)
                  {
                      this.selectedSpriteTxt.text = actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite.toString();
                  }
                  this.outputTxt.text = this.canvas.describeChildren();
              } 
              
                      public function moveToBack():void
                      {
                          if (actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite != null)
                          {
                              this.canvas.moveToBack(actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite);
                              this.outputTxt.text = this.canvas.describeChildren();
                          }
                      }
                      
                      public function moveDown():void
                      {
                          if (actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite != null)
                          {
                              this.canvas.moveDown(actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite);
                              this.outputTxt.text = this.canvas.describeChildren();
                          }
                      }
   
                       public function moveUp():void
                      {
                          if (actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite != null)
                          {
                              this.canvas.moveUp(actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite);
                              this.outputTxt.text = this.canvas.describeChildren();
                          }
                      }
                                         
                      public function moveToFront():void
                      {
                          if (actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite != null)
                          {
                              this.canvas.moveToFront(actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_GeometricSprite.selectedSprite);
                              this.outputTxt.text = this.canvas.describeChildren();
                          }
                      }
          ]]>
      </mx:Script>
      
           <mx:Label id="title" text="Sprite Arranger Example" fontSize="24" fontStyle="bold" />
          <mx:Text id="subtitle" text="From Programming ActionScript 3.0, Chapter 12: Display programming" width="100%" textAlign="center" fontSize="12" />
      
      <mx:Panel title="Add and Arrange Shapes" verticalGap="0">
  
          <mx:ControlBar width="100%" horizontalAlign="center" borderStyle="outset" backgroundColor="0xEEEEFF">
               <mx:Label text="Shape to add:" /> 
               <mx:ComboBox id="shapeNameCbo">
                   <mx:dataProvider>
                      <mx:Array>
                         <mx:String>Circle</mx:String> 
                         <mx:String>Triangle</mx:String> 
                         <mx:String>Square</mx:String> 
                      </mx:Array> 
                   </mx:dataProvider> 
               </mx:ComboBox>
             
             <mx:Label text="Size in pixels:" />
             <mx:NumericStepper id="shapeSizeNs" minimum="10" maximum="100" stepSize="10" value="50"/>
      
             <mx:Button id="addBtn" label="Add Shape" click="addShape()"/> 
             
          </mx:ControlBar>
          
          <mx:VBox width="100%" height="100%" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" backgroundColor="0xEEEEFF">
              
              <mx:HBox width="100%">
                  <mx:Label text="Drawing area:" width="100%" />
                  <mx:Spacer width="100%" />
                  <mx:Button id="moveToBackBtn" label="Move to Back" click="moveToBack()" />
                  <mx:Button id="moveDownBtn" label="Move Down" click="moveDown()" width="80" />
                  <mx:Button id="moveUpBtn" label="Move Up" click="moveUp()" width="80" />
                  <mx:Button id="moveToFrontBtn" label="Move to Front" click="moveToFront()" />
              </mx:HBox>
              
              <example:actionscript_book_SpriteArranger_com_example_programmingas3_spritearranger_DrawingCanvas id="canvas" width="500" height="200" mouseUp="describeShapes();" mouseDown="describeShapes();" />
              
              <mx:Label text="Child display objects:" width="100%" />
              <mx:TextArea id="outputTxt" width="100%" height="120" editable="false" />     
   
              <mx:HBox width="100%">
                  <mx:Label text="Selected sprite:" />
                  <mx:Label id="selectedSpriteTxt" text="none" />
              </mx:HBox>   
                  
          </mx:VBox>   
      </mx:Panel>
  
  </mx:Application>
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.