Archive

Archive for the ‘ActionScript 3’ Category

AS3 framework option #3

January 24th, 2012 3 comments

After analyzing 2 most popular framework both from syntax and performance point of view – I realized that both frameworks is not good enough for me. I work mainly with games and heavy applications that requires both code writing speed and code execution speed. With that knowledge I did what any programmer usually does in such situation – started my own project! where everything will be perfect! it will be fast! it will be comfortable to work with! and sun will shine all day long!

So I started with writing requirements…

Read more…

RobotLegs VS PureMVC: performance battle!

January 6th, 2012 1 comment

We all know that using framework in you application will hurt performance, and Flash has long and sad history of performance problems. I decided to find out how much exactly performance using framework costs us. As in last post I focus on 2 most popular frameworks: RobotLegs and PureMVC.


Run PureMVC tests           [Source code: PureMVCSpeedTest.zip]

I tried to measure 4 things: running commands, getting stuff, creating mediators, communication.
I measured how much time one such action will take, and calculated how much actions you can use in your code to waste 1ms of execution time.

PureMVC VS RobetLegs match-up!

December 14th, 2011 1 comment

Then you start creating bigger applications, or start working in bigger teams – using good framework becomes essential.
I spent good amount of time with 2 currently most popular AS3 frameworks – PureMVC and RobotLegs, and here I will compare pros and cons of both.



Generally both frameworks are very similar! :


RobotLegs and PureMVC Pros:

  • will help divide your code is small units and wire them;
  • will help standardize your code;
  • based on MVC;
  • can be extended to your needs;
  • makes you focus on your fun app instead of focusing on solving architecture puzzles;
  • have big and active communities;



RobotLegs and PureMVC Cons:

  • hurts performance a bit;
  • harder to debug “black box” framework code;
  • couples implementation with framework;



…but RobotLegs: Read more…

Magic there FlashDevelop meets PureMVC

October 6th, 2011 No comments

I work with PureMVC - very popular and flexible framework .

Another tool that lets you enhance your work is FlashDevelop, it’s free, it has amazing templates and snippets to speed your work.

Now imagine what happens then those 2 meet each other. MAGIC HAPPENS!

There are couple of things that makes writing PureMVC not fun. That is:

  • Creating proxies, mediators and commands. They must be written as framework demands it.
  • Getting your mediators and proxies also annoys. It’s lot of typing – all this getting and casting…

Luckily with FlashDevelop file templates and snippets you totally remove the hassle of doing those not fun things in PureMVC!

Class templates: DerilsPureMvcTemplates.zip

this has to be unzipped to :  your “Application files” folder  - …\Templates\ProjectFiles

I will explain couple of things. That is special to my ‘style’ of using PureMVC.

  • I name ‘notice’ for notification object. I use class “Note”,”ViewNote”, “DataNote” as constant holders. I wanted to separate those for quicker typing/code hinting. Just rename it in mediators and commands if you use something else.
  • There are 2 variations of mediator and 2 variations of proxy, one with data/viewComponents sent to super class, and one that just keeps it locally. I rarely set it to super class, but sometimes it’s needed.
  • I don’t bother casting data or viewComponent to it’s data type, and never will, I store them locally with needed type. Cast object every time you need to use it is a total nonsense, the only danger is setting different object for custom and super classes, but that’s easily fixed ovverideng setData/setVeiwComponent functions. What I did in templates.
  • Code style: brackets on the line, package is not intended.

 

Snippets:

Get proxy(I named it “!retrieveProxy”):

var $(EntryPoint)$(CurWord):$(CurWord) = facade.retrieveProxy($(CurWord).NAME) as $(CurWord);

Get mediator(I named it “!retrieveMediator”):

var $(EntryPoint)$(CurWord):$(CurWord) = facade.retrieveMediator($(CurWord).NAME) as $(CurWord);

 

Usage scenario:

  • ctrl+alt+ space to get class hinting
  • write and pick class (mediator or proxy)
  • use one or another snippet (I use keyboard shortcuts through macros)
  • press delete to delete first letter.
  • write deleted letter in lower case.

I create macro to use those snippets and map them on CTRL+ALT+1 and CTRL+ALT+2;

They look like this:

InsertSnippet|!retrieveProxy
InsertSnippet|!retrieveMediator

: initialize note constant quickly.
Depricated. I was using snippet to generate constants quicker:

$(CurWord):String = “$(CurWord)”

but lates FlashDevelop 4.0.0 RC1 does it automaticaly now.

Have fun.

AS3 KeyboardEvent stage focus problem solution

August 3rd, 2011 No comments

So I needed global KeyboardEvent handling in AS3 project, but ran into problem – stage losses focus in couple of scenarios..

The fact that flash has no global object that never loses focus just SUCK!!!

I found in documentation that in Flex you can put your event on application object and solve this problem, but because I hate Flex – I can’t be bothered.

So possible solution I found all over the internet is force focus back to stage:

stage.focus = stage;

But this method creates another problem if you actually need focus on something not stage.(like text input fields).

My approach makes KeyboardEvent listeners travel with focus, from object to object that gets it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package {
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.FocusEvent;
import flash.events.KeyboardEvent;
 
public class KeyBoardFocusMain extends Sprite {
 
	private var focusObject:InteractiveObject;
 
	public function Main():void {
		setFocusObject(this.stage);
	}
 
	private function setFocusObject(newFocusObject:InteractiveObject):void {
		if (focusObject){
			focusObject.removeEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
			focusObject.removeEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
			focusObject.removeEventListener(FocusEvent.FOCUS_OUT, handleFocusChange);
		}
		focusObject = newFocusObject;
		//
		focusObject.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
		focusObject.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp);
		focusObject.addEventListener(FocusEvent.FOCUS_OUT, handleFocusChange);
	}
 
	private function handleFocusChange(event:Event = null):void {
		if (focusObject != stage.focus){
			if (stage.focus != null){
				setFocusObject(stage.focus);
			} else {
				setFocusObject(stage);
			}
 
		}
	}
 
	private function handleKeyUp(event:KeyboardEvent):void {
		trace("handleKeyUp:", event);
		switch (event.keyCode){
			//...
			default: 
				break;
		}
	}
 
	private function handleKeyDown(event:KeyboardEvent):void {
		trace("handleKeyDown:", event);
		switch (event.keyCode){
			//...
			default: 
				break;
		}
	}
 
}
}

Hope it helps, have fun.

AssetLibrary : basics

July 28th, 2011 No comments

I want to post series of articles about tool I am building during free time.

All started then I got this insane idea of building GUI library, for creating GUI in applications more fluently and conversant then FLEX. (there is so much things I hate about FLEX…)
I needed a asset library to handle my assets easily. I starter with something simple, but ended up having a lot of features I initially didn’t planed.

Read all features here : http://code.google.com/p/msa-lib/

I will write couple of posts about this library, and transform them to documentation.

If it’s something that interests you, grab code in http://msa-lib.googlecode.com/svn/trunk/ and lets get started.


Then you build application, you almost always have some sort of assets: texts, images, sounds, binary files for 3d and so on.

 

I am dividing those assets in 3 category:

  • Internaly embedded assets.
  • External permanent asset. (it’s loaded once, usually in the beginning, and then never removed from memory. )
  • External temporal asset. (it’s loaded then needed, and unloaded then not needed any-more.)

Then you deal with internally embedded assets, there is not much to do with them, you just use it then you need it. With external assets its a bit trickier, that’s there AssetLibrary comes in.

 

Lets just start with most simple example possible:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package examples {
import com.mindscriptact.assetLibrary.AssetLibrary;
import com.mindscriptact.assetLibrary.AssetLibraryIndex;
import flash.display.Sprite;
 
public class MinimalLoad extends Sprite {
 
	public function MinimalLoad(){
 
		// add assets to library.
		var assetIndex:AssetLibraryIndex = AssetLibrary.getIndex();
		assetIndex.addFileDefinition("test1", "assets/simpleTest/test1.swf");
 
		// load asset and send it to function.
		AssetLibrary.sendAssetToFunction("test1", handleTest1);
	}
 
	private function handleTest1(asset:SWFAsset):void {
		// get instance of object linked in asset library.
		var testSprite:Sprite = asset.getSprite("SquareA_SPR");
		this.addChild(testSprite);
		testSprite.x = 100;
		testSprite.y = 100;
	}
 
}
}

 
To use external assets you need to define them first. AssetLibraryIndex class is created for that.
To get it’s instance you need to call AssetLibrary.getIndex() function. In most cases you will be defining you assets once, and then application starts. After assets are defined you most likely will never use this class again. AssetLibraryIndex class lets you define folders, groups, add file definitions from xml file, and add single file definitions, lets start with those.

Every file definition in AssetLibrary needs an Id. This id is used to work with asset instead of all it’s de-tales like url, asset type, how it’s loaded and such. Most simple asset has id and url. To add asset we use assetIndex.addFileDefinition(); function.

Now then asset is defined we can start using it. We tell AssetLibrary to load it and send asset as parameter to function. We use AssetLibrary.sendAssetToFunction() for that. This function expects assedId and function to send asset to.

Then we write asset handling function we must remember, that same as event handling function gets an event object as parameter, asset handler gets asset as parameter. Because we are using swf asset, we will get SWFAsset class object. This object can be used to get any instance of symbol in assets library. We need to know the type of linked object and its ActionScript linkage class.


Next time I explain how permanent and temporal assets differ, and how to track loading progress with this tool.

Away 3d materials

April 19th, 2009 1 comment

I have prepared Away 3d material showdown example. It took  awhile.. its just lot of work finding new job and all..
I have tried to write it in such a way.. that I could use it as a draft to create materials in my work. 

away3dmaterials_swf

[ SOURCE :  a3dMaterials.zip] OR [ A3dMaterial.as ]

Again.. I feel like I can make good tutorial/reference file out of this.. so… stay in touch.

Categories: ActionScript 3, AWAY 3d, Flash Tags:

AWAY 3D (v2.3) class diagram

March 5th, 2009 No comments

So… I was wondering witch class of AWAY 3d to gut next… end decided to create a quick class diagram to see hole picture. I use Enterprise Architect for application modeling and AS3 code generation, so I used it here, and produced picture so big that I end up creating flash application just to view it.. :)

I hope you will find this diagram useful.

away3dclassdiagram

Stand alone image : Away_3d_Class_diagram.png

( PS : maybe you know application that exports diagrams as swf? )

Categories: ActionScript 3, AWAY 3d, Flash Tags:

My dive to third dimension

March 1st, 2009 No comments

I have been thinking about 3d in flash for a long time.. but it always seemed that its still not a good time: flash is too weak. or 3d engines had not enough power. But I always knew.. that day will come for me to dive in 3d world.
I have spend that day examining 3d engine list and end up in choosing between two most powerful open source engines : PaperVision and AWAY 3d . I know that PaperVision is more popular, but it seemed to me that currently AWAY 3d is at least one step ahead. I am sure I will learn PaperVision then time will come.. but for naw – I present you my first work in AWAY 3d.

I like learning stuff orderly and without rush, so it was naturally for me to start with exploring 3d primitives and what can be done with them. I started by reading nice flashmagazine.com tutorials for AWAY 3D and then with AWAY 3D livedocs at my side I come up this this result:

away3dprimitives_swf

[ SOURCE: A3dPrimitives.as ]

(I use FlashDevelop with Flex SDK for coding…)

You will find instantiation for all away 3d primitives, and my draft of Object3D class possibilities. Some stuff I skipped as it involves topics I am planing to learn in the future.. or simply something I fail to understand, so I put all that in ‘unknown’ section. 
I will update this draft with hopes that it may be useful for someone.. or maybe turn it to tutorial of some sort.

… next step… textures!

Categories: ActionScript 3, AWAY 3d, Flash Tags:

MindScriptAct is Stephen Fry proof thanks to caching by WP Super Cache