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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 3-5. BadImplementation.as (continued)<br />

}<br />

{<br />

}<br />

public function BadImplementation( )<br />

{<br />

var mySingleton=new Singleton( );<br />

}<br />

Save the file as BadImplementation.as in the same folder as the Singleton.as. Ina<br />

Flash document, type in BadImplementation in the Document class window, and test<br />

the application. As predicted, you get a <strong>com</strong>piler error as shown in Figure 3-2.<br />

Figure 3-2. Compiler error expecting argument<br />

Immediately you see that the Singleton constructor contains an argument, a<br />

PrivateClass, and so the natural response is to change the code to include a<br />

PrivateClass argument as shown in Example 3-6.<br />

Example 3-6. Attempt to add private class parameter<br />

package<br />

{<br />

import flash.display.Sprite<br />

public class BadImplementation extends Sprite<br />

{<br />

public function BadImplementation( )<br />

{<br />

var mySingleton=new Singleton(new PrivateClass( ));<br />

}<br />

}<br />

}<br />

Re-save the BadImplementation.as file and test it again. This time, you get a different<br />

error as shown in Figure 3-3:<br />

Minimalist Abstract Singleton | 107

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

Saved successfully!

Ooh no, something went wrong!