ActionScript 3.0 Design Patterns

(Chris Devlin) #1

38 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0


Example 1-33 introduces something new. ThePlasmaclass extends one class,Sprite,


and implements another,IBiz. Placing a video on the stage requires a Sprite object,


but we still need the IBiz interface methods; so using both the extends and


implements statements, we’re able to have the best of both worlds.


Example 1-32. IBiz.as


package
{
public interface IBiz
{
function productDescribe( ):String;
function productPrice(price:Number):String;
function productDisplay(product:String):void;
}
}


Example 1-33. Plasma.as


package
{
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.display.Sprite;


public class Plasma extends Sprite implements IBiz
{


private var ns:NetStream;
private var vid:Video;
private var priceNow:Number;


public function productDescribe( ):String
{
return "42 inch TV with Plasma screen";
}


public function productPrice(price:Number):String
{
priceNow=price;
return "$" + priceNow + "\n";
}


public function productDisplay(flv:String):void
{
var nc:NetConnection=new NetConnection( );
nc.connect(null);
ns=new NetStream(nc);
ns.play(flv);
vid=new Video( );
vid.attachNetStream(ns);
addChild(vid);

Free download pdf