<< Chapter < Page Chapter >> Page >

The overridden play method produces the desired effect

Later on you will see that the driver class for this program instantiates an object of the custom effect class and calls the play method on that object. At that point, the driver class will be calling the method thatbegins in Listing 9.

Set the required properties on the three standard effects

Listing 9 uses the values that were stored in the variables in Listing 7 by the initInstance method in Listing 4 to set the required properties for each ofthe three individual effects that will be combined to produce this custom effect.

Ordinarily, you might think that this could have been accomplished in the constructor for the class. However, the values in the variables in Listing 7aren't stable until the constructor has finished constructing the object. Therefore, it is necessary to defer the assignments in Listing 9 until after theconstruction of the object is complete.

Play the three effects in parallel

You learned how to use an object of the Parallel class to play two or more effects in parallel in the earlier lesson titled Events, Triggers, and Effects .

Play the three effects in parallel.

//Play all three effects in parallel. var parallel:Parallel = new Parallel();parallel.addChild(rotateEffect); parallel.addChild(glowEffect);parallel.addChild(wipeEffect); parallel.play();} //end play //--------------------------------------------------//} //end class } //end package

Therefore, you shouldn't have any difficulty understanding the code in Listing 10.

Steps required to create a custom effect

You must define a factory class and an instance class. The following steps are required to create and prepare the factory class:

  • Define a factory class that extends the Effect class.
  • Declare variables in the factory class, if any are required, to store the property values for the custom effect.
  • Define a constructor for the factory class that calls the constructor for the superclass and also sets the name of the instance class into the inheritedvariable named instanceClass .
  • Override the initInstance method in the factory class to store the property values into variables in the instance class. Also call the initInstance method of the superclass in that overridden method.
  • Override the getAffectedProperties method in the factory class to return a list of target component properties that will be modified bythe effect. Return an empty array if none will be modified.

Define and prepare the instance class

Having defined the factory class using the steps listed above, define the instance class by performing the following steps:

  • Define an instance class that extends the EffectInstance class.
  • Declare public instance variables for the storage of effect property values if any are required.
  • Define a constructor for the instance class that deals appropriately with the target component.
  • Override the inherited play method to implement the actual behavior of the custom effect.

The end of the CustomEffectInstance class

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask