Subscribe

  • Subscribe  

Creating Graphics Copies with ActionScript3

Posted by Jay | May 10, 2008 .

Since ActionScript3 is the core to Flash/Flex RIA it contains an expansive repertoire of display objects, graphical methods to create such applications. At the same time for design of such an application may need replication of same object several times. E.g. virtual pool table

With AS3, in order to duplicate the properties of a Display object instance to other instances, the “GraphicsCopy” class provides for an easier approach. It substitutes the graphics properties of an instance to other instance.

Public function GraphicsCopy (graphics:Graphics = null) // constructor

The Graphics instance in the parameter list that receives all drawing calls through drawing API (e.g. graphical property like color, line style) and returns it to the GraphicsCopy class instance thereby coping the stuff from one object to other instance through use of Copy method. The essentially creates a GraphicsCopy class instance and initializes its graphic properties in constructor of the class (displayobject instance) whose object has to be duplicated. Then use copy method of GraphicsCopy object to copy the values to new instance.

package {

  import flash.display.Shape;

  import com.examplee.display.GraphicsCopy;  class circle extends Shape

  {

    public function get graphicsCopy():GraphicsCopy {

      return gc1;

    }

// constructor

   function circle(){

     private  var gc1 = new GraphicsCopy(graphics);

   }

}

var circle 1: circle = new circle ();

var circle 2: circle = new circle ();

circle1.drawCircle(100, 120, 50);

this.addChild(circle1);  // add to display list

circle2.graphicsCopy.copy(circle1.graphicsCopy); //call copy method of graphicscopy class

}

Leave a Comment

If you would like to make a comment, please fill out the form below.


Name

Email

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Comments

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word


Related Posts

1 Comment so far
  1. web developer  October 8, 2009 9:42 pm
<

Direct TV Offers - usdirect has the best directtv deals