10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example 1-32. IBiz.as<br />

package<br />

{<br />

public interface IBiz<br />

{<br />

function productDescribe( ):String;<br />

function productPrice(price:Number):String;<br />

function productDisplay(product:String):void;<br />

}<br />

}<br />

Example 1-33 introduces something new. The Plasma class extends one class, Sprite,<br />

and implements another, IBiz. Placing a video on the stage requires a Sprite object,<br />

but we still need the IBiz interface methods; so using both the extends and<br />

implements statements, we’re able to have the best of both worlds.<br />

Example 1-33. Plasma.as<br />

package<br />

{<br />

import flash.net.NetConnection;<br />

import flash.net.NetStream;<br />

import flash.media.Video;<br />

import flash.display.Sprite;<br />

public class Plasma extends Sprite implements IBiz<br />

{<br />

private var ns:NetStream;<br />

private var vid:Video;<br />

private var priceNow:Number;<br />

public function productDescribe( ):String<br />

{<br />

return "42 inch TV with Plasma screen";<br />

}<br />

public function productPrice(price:Number):String<br />

{<br />

priceNow=price;<br />

return "$" + priceNow + "\n";<br />

}<br />

public function productDisplay(flv:String):void<br />

{<br />

var nc:NetConnection=new NetConnection( );<br />

nc.connect(null);<br />

ns=new NetStream(nc);<br />

ns.play(flv);<br />

vid=new Video( );<br />

vid.attachNetStream(ns);<br />

addChild(vid);<br />

38 | Chapter 1: Object-Oriented Programming, <strong>Design</strong> <strong>Patterns</strong>, and <strong>ActionScript</strong> <strong>3.0</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!