I’ve created kind of a project review to see ‘big picture’ (; Lot of classes in use so I needed a place to review and check some basic features. At this point there are some things I would like to improve and optimize (or change if necessary). Code of this review is description of what classes do, with descriptions of some important properties and methods. When I write [COLOR=red]stage.enterFrameHandler():updateChange()[/COLOR] - that means, [COLOR=red]stage[/COLOR] listens to [COLOR=red]Event.ENTER_FRAME[/COLOR] and handler is function [COLOR=red]enterFrameHandler()[/COLOR]; inside handler there are some conditions and if they are met [COLOR=red]updateChange()[/COLOR] is called. Hope you can understand it… This is the project, basicly.
class Default(), extends Sprite
// get = connect & query MySQL database
// add = create instance of an object
// load = load .swf file
// show = display objects
/* variables */
// public example; private _Example;
// protected _example; internal __example
1 > get application settings
2 > add _AppShell:Shell
3 > load defaultSkin.swf
3 > add _AppSkin:Skin
4 > get page // url?pageID=e22Ob2fs51
5 > add assets = [__asset01:Asset, ..., __asset15:Asset]
5 > show assets
class Shell(), extends Sprite
_Background:DisplayObject
_Foreground:Sprite
stageResizeHandler():void
_Background.width; _Background.height
_Foreground.align()
>>> reflect events
recieve CoreEvent(bubble=true), child.dispatchEvent(CoreEvent)
class Skin(), extends Loader
// static definitions of object properties and skins
DEFALUT_COLOR:Number = 0xEEEEEE;
GenericButton:Class = _loader.appDomain.getDefinition("lib.GenericButton") as Class;
TextFormats:Class = _loader.appDomain.getDefinition("lib.TextFormats") as Class;
textFormats = new TextFormats();
pageTitleFormat:TextFormat = TextField(textFormats.pageTitleFormat).defaultTextFormat;
class Spright(), extends Sprite
// used as abstract class - never directly instanciated
_Background:DisplayObject
_Mask:DisplayObject
_HitArea:Sprite // !!!
>>> ENGINE <<<
// adopted from fl.core.UIComponent
registerChange(property:String = PropertyChange.MARGIN, updateNow:Boolean):void
// if (updateNow) updateChange() else stage.enterFrameHandler():updateChange() // !!!
hasChanges(...properties):Boolean
resetChanges():void
updateChange():void
// if (PropertyChange.MARGIN) updatePosition()
// if (PropertyChange.ALIGN) updateLayout()
>>> get/set
align:String, attach:String, sibling:DisplayObject,
// Align.objects(this, sibling, Align.TOP_RIGHT)
// this.attachTo(sibling:DisplayObject, Attach.LEFT_BOTTOM)
// Attach.objects(this, sibling, Attach.LEFT_BOTTOM)
padding:Object.<int>, margin:Object.<int>, lock:Object.<Boolean>
background:DisplayObject, animated:Boolean
>>> overrides
x, y, width, height, mask, hitArea, root
addChild(), removeChild()
// addChild >>> if (_childOverride:Boolean) child.visible = false;
addedToStageHandler():void
// registerChange(PropertyChange.ALL);
class Control(width:Number = 0, height:Number = 0), extends Spright
// handles style, type, validation, focus
_Patern:RegExp // validation
>>> get/set
style:Style, type:Type, valid:Boolean, focusObject:DisplayObject
>>> overrides
updateChanges():void
class Label(), extends Control
class Button(states:SimpleButton = new Skin.GenericButton()), extends Control
>>> get/set
toggle:Boolean, down:Boolean
reset():void
....
....
class TextInput(), extends Control
>>> get/set
maxChars:int
submit():CoreEvent.SUBMIT
class Container(width:Number = 0, height:Number = 0), extends Spright
// empty container with properties from Spright...
class SizeEditor(), extends Container
_Width:TextInput, _Height:TextInput, etc
class Component(width:Number = 0, height:Number = 0), extends Spright
// few extra properties...
class ButtonBar(), extends Component
>>> get/set
layout:Layout, down:Boolean
clickHandler():CoreEvent.CLICK
// for each (button:Button in _Buttons:Array) if (event.target != button) button.reset()
class EditMenu(), extends Component
_SizeEditor:SizeEditor, _Buttons:ButtonBar, etc
class Login(), extends Component
_Username:TextInput, _Password:TextInput, _Submit:Button, etc
....
....
....
class Asset(), extends Component
_Title:Label, _EditMenu:EditMenu, _Image:Media, etc
here are few questions:
1. “Reflecting” Events: what’s best way to do this? If you look at the project structure [COLOR=blue]Asset[/COLOR] class is a display object that is added to stage. It’s created using content from database and contains lot of other objects. If I move an [COLOR=blue]Asset[/COLOR] on stage [COLOR=blue]Shell[/COLOR] will recieve [COLOR=red]CoreEvent.MOVE[/COLOR] and should dispatch it to other Assets that are ‘connected’ to this one. Which brings me to the next question
2a. Detecting when object creation is complete: how can I be sure if object ‘creation’ is complete? For example if I make [COLOR=blue]Button[/COLOR] I would set some of the properties (not all) I need:
// example 1
var button:Button = new Button();
button.width = 50;
button.toggle = true;
addChild(Button);
// example 2
var button:Button = new Button();
addChild(Button);
button.width = 50;
button.toggle = true;
Using the ‘engine’ I riped off from fl.core.UIComponent (they call it invalidate/validate, I used propertyChange/resetChange) both of these examples will work in my code. I need some way to detect when [COLOR=blue]Button[/COLOR] is created, so I can stop updating it when changes happen on other, connected objects. But I can’t figure out right way to do it. Any ideas?
2b. Delaying updates: the ‘engine’ I’m using is using [COLOR=red]Event.ENTER_FRAME[/COLOR] to ‘wait’ for property changes. For example, I want to set background to red, but width and height of object are not yet set. So when I add backround = 0xFF0000, engine adds ENTER_FRAME listener and waits… When width and height are set, red background is created and listener is removed. I ran into few situations where I wanted to use some other method to delay update, but couldn’t figure out how. Creating [COLOR=blue]Timer[/COLOR] didn’t seam like a good idea at the time I tried (tho’ I don’t know why now LOL). Anyway, any other approaches to this?
3. Skinning: I’m using .swf files to skin my objects. It works really nice - creating objects in Flash IDE and using them in my AS3. Easy to change skins too. I was wondering how would you deal with skinning issue.
4. Abstract Class: I would like to make my [COLOR=blue]Spright[/COLOR] trully abstract class (for example extending [COLOR=blue]DisplayObjectContainer[/COLOR]), but I really need [COLOR=red]hitArea[/COLOR] property from Sprite. And I don’t know how to extend both [COLOR=blue]Spright [/COLOR]and [COLOR=blue]Sprite [/COLOR]in my [COLOR=blue]Component[/COLOR] class (; Any ideas?
Hope my ‘code’ isn’t too confusing (: Think of it as [COLOR=blue]Interface[/COLOR] with benefits I really couln’t thing of a different way to show some thousand lines of code in 150 lines xD If you can see what’s going on here, fell free to comment and/or suggest some other way to do things…