Posts Tagged ‘AS3’

Sprouts

June 26, 2008

Whilst searching for information about MTASC Commands I came across site the Sprouts site. An ‘an open-source, cross-platform project generation and configuration tool for ActionScript 2, ActionScript 3′…. As I’ve been looking at Ruby using the OSX Terminal and am interested in further experiments in finding new an better ways to compile and build swfs I thought I would investigate, and create another project.

Project Aims:

1. Create a Sprout to compile AS2 Flash to a swf using MTASC.

2. As above with SWFMill

The Project uses:

1. Mac OSX 10.4.11

2. Flash 8

3. AS2

4. Ruby ruby 1.8.6 (Once updated)

5. RubyGems

6. OSX Terminal (I’m using the $ symbol to denote input into the Terminal Window, ie type what’s after the $ glyph).

Tasks

1. Ascertain which version of ruby is installed. In the Terminal type:

$ ruby -v

which for me outputs:

ruby 1.8.2 (2004-12-25) [universal-darwin8.0]

2. Update Ruby. The latest version is

ruby 1.8.6

so if current version is less you need to update. I used the Ruby One-Click Installer for OSX. Downloaded and unpacked in the Terminal, opened a fresh Terminal window and typed in the Terminal:

$ ruby -v

The output is now:

ruby 1.8.6 (2007-03-13 patchlevel 0) [universal-darwin8.0]

3. Install RubyGems.

Down load and unpack. ( I put the ‘rubygems-1.2.0′ folder in Applications.)

4. Install Rails.
In the Terminal Window:

$ sudo gem install rail

Enter password if prompted. My Terminal output was:

Bulk updating Gem source index for: http://gems.rubyforge.org
ERROR: While executing gem … (Gem::GemNotFoundException)
Could not find rails (> 0) in any repository

(I’m not 100% sure if everything was OK here, or if this step was necessary, so I’ll have to make some further investigations.)

5. Install the sprout gem. Enter in the terminal:

$ sudo gem install sprout

The Terminal Output was:

Bulk updating Gem source index for: http://gems.rubyforge.org
Select which gem to install for your platform (universal-darwin8.0)
1. sprout 0.7.183 (ruby)
2. sprout 0.7.183 (darwin)
3. sprout 0.7.183 (mswin32)
4. sprout 0.7.183 (x86-linux)
5. Skip this gem
6. Cancel installation

Just guessing entered:

$ 1

A whole load of other options followed such as:

Install required dependency rubyzip? [Yn]

I entered Y for all of them.

Various outputs followed for example:

Successfully installed sprout-0.7.183
Successfully installed rubyzip-0.9.1
Successfully installed archive-tar-minitar-0.5.2
Successfully installed rails-2.1.0
Successfully installed rake-0.8.1
……

So I assumed the correct applications have been successfully installed.

6. Instructions for downloading the Sprouts AS2 Bundle see: ActionScript 2.0 Bundle

For example in the Terminal

cd

to an appropriate folder and enter:

$ sprout -n as2 SomeProject

7. Launch Rake

$ rake

Had some problems tried, output:

rake aborted!
no such file to load — open4

I was getting a message:

sudo gem install open4

8. Sort out Rake problem
Found some advice here: projectsprouts

Enter in the Terminal:

$ sudo gem install open4

Then after a whole load of output:

sudo gem install rb-appscript

9. Launch Rake again

$ rake

After another string of output, the Flash Player launched with the png of the Sprout logo!

Picture 1.png

Conclusion:

The project first aim …compile AS2 Flash to a swf… has been realised, I’ll create further posts to detail further experiments.

Flash Programming - Good Articles

June 20, 2008

I’m compiling a collection of links to good Flash Programming articles, I’ll add some more details soon.

Explaining OOP without Mentioning Classes

I’m currently documenting a Flash project and whilst I was looking for precise definitions of Programming terms came across a definition of the Law of Demeter. This is (t)he fundamental notion is that a given object should assume as little as possible about the structure or properties of anything else… This is something I’ve been attempting to do without having a name for it for some time, i.e.. a Class should know as little as possible.

To quote again from this article a point pertinent to ActionScript: In particular, an object should avoid invoking methods of a member object returned by another method. For many modern object oriented languages that use a dot as field identifier, the law can be stated simply as “use only one dot”. That is, the code “a.b.Method()” breaks the law where “a.Method()” does not.

There is a good example explaining the Law of Demeter using Ruby see: Misunderstanding the Law of Demeter.

MVC

May 22, 2008

I been interested in the MVC design pattern for some time and will now attempt to document and create links my knowledge.

I originally created a MVC framework closely following the Mook MVC pattern in Essential ActionScript 2.0.

A working example can be downloaded at: MVC Clock.

There seem to be many more AS3 versions of MVC, varying in complexity.

The O’Reilly Essential ActionScript 3.0 by Mook provides an example using a Composite Pattern. A PDF of the MVC chapter can be found at the Adobe devnet site.

Also there is an open source framework called Pure MVC, which provides the framework in a variety of programming languages, including AS3.

There are various tutorials for using Pure MVC see: hubflanger

Loading External swf and establishing Class Visiblity

May 20, 2008

I was creating a Flash 9 App for a client, the app was working fine. But, the client requested to the app to play a pre existing introduction.swf and then continue as before.

My strategy was to load a separate swf from the Main swf and then remove it when it had reached a certain point, and continue with the Main swf.

To implement this I used the Flash 9 Loader class and the ExternalMovie Class.

The Main Document Class loads the introduction.swf by the calls:

loader = new Loader();

var urlRequest:URLRequest=new URLRequest(”introduction.swf”);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);

loader.load(urlRequest);

The onCompleteHandler() Method assigns the clip var and adds it to the DisplayList, and establishes a reference with the swf:Object instance, so the events can be listened to.

private function onCompleteHandler(loadEvent:Event) : void{

clip = loadEvent.currentTarget.content;

addChild(clip);

var loaderInfo:LoaderInfo = loadEvent.target as LoaderInfo;

var swf:Object = loaderInfo.content;

swf.addEventListener(Event.COMPLETE, onIntroCompleteHandler);

}

The swf to be loaded has it’s Document Class set to ExternalMove. When the introduction.swf reaches a certain from it calls a method animationComplete(). The animationComplete() method dispatches an Event.COMPLETE.

This is the Event which the Main Document Class is waiting for, and the onIntroCompleteHandler() Method is called, which removes the introduction.swf and continues with the Main Movie.

private function onIntroCompleteHandler(event:Event):void{

removeChild(clip);

loadMcg(); // continues with Main Movie

}

papervision

May 5, 2008

I’ve recently worked on a couple of Papervision3d sites.

Below is a list of links I’ve found useful:

papervision3d.org

papervision2 which has excellent tutorials.

Problems with navigateToUrl

May 5, 2008

Whilst working on a Papervision3d project, I was having a little trouble linking to external web links.

I Found an excellent solution here: Problems using navigateToURL. This solution incorporates the use of a Class URLUtils written by Jason the Sajand and uses the SWFObject.

A link to the latest version of the SWFObject can be found here: SWF Object