Posts Tagged “class”

Two new releases today, an asset loader and the SomaCore plugin: SomaAssets.

The AssetLoader library is a port from Matan's AssetLoader library to be event-based, it makes you able to load and manage multiple assets (image, video, xml, sound, etc) in your application.

SomaAssets is a plugin based on the AssetLoader library to easily access to your assets and effectively integrate them in your SomaCore application with paths and automatic mapping name generation for injection.

Special thanks to Matan for his help with the AssetLoader and his joy in general, a pleasure to "meet" him.

You can read the SomaAssets wiki section to get started with it, but I'll post below a few hints of what you can easily do with it within a SomaCore application.

AssetLoader source
AssetLoader wiki
SomaAssets source
SomaAssets wiki

Easily create the plugin and add a XML config file for the assets.

Actionscript:
  1. createPlugin(SomaAssets, new SomaAssetsVO(this, "xml/assets_config.xml"))

Easily retrieve the assets with paths through the XML config.

Actionscript:
  1. var image:Bitmap = assets.getAssets("group0/group00/img0");

Easily retrieve the plugin, main loader, config and assets with injection in a SomaCore application. The following mapping names have been automatically generated from the XML config.

Actionscript:
  1. [Inject(name="assets")]
  2. public var plugin:SomaAssets;
  3.  
  4. [Inject(name="assets")]
  5. public var loader:IAssetLoader;
  6.  
  7. [Inject(name="group0/group00/img0")]
  8. public var loaderType1:ImageLoader;
  9.  
  10. [Inject(name="group0/group00/img0")]
  11. public var assetType1:Bitmap;

Vote in HexoSearch

Comments 3 Comments »

BinderUI is a debugging tools to help you create interfaces and debug values.

Very often I’m sure you spend time building visual interfaces to set, to see and to debug some values.
This can be useful for example to show to the creative (or even the client?) and extract the right values instead of tweaking thing for ages, I’m sure you know what I mean.

That can be time consuming and is often very annoying so I wanted to ease the process (1 line of code and a metadata tag).

BinderUI is a simple static class and the idea is to “bind” a value to visual components such as slider, knob, meter, text input, and so on. For the components I used the library minimalComps.

That means that the bound values will update the components in real-time and the components will update the values (two-ways). I used the BindingUtils and ChangeWatcher classes from the mx package but as it will be for debugging, you can use it on project that will be pure AS3 as well.



Click here to see the demo.

As a quick example, imagine you have a custom darkness property on your custom class, you can bind the value this way:

Actionscript:
  1. BinderUI.displaySliderHorizontal(this, _mySprite, "darkness", "darkness", null, 0.1, 1, -255, 255);

This will create a slider that will update (and be updated) for your darkness property.

You’ll also need to add a Bindable metadata in your class:

Actionscript:
  1. [Bindable]
  2. public class MySprite extends Sprite {

Note: in case you want to debug built-in flash properties (such as x and y), you’ll need to override the properties in your custom class even if it does nothing.

Actionscript:
  1. override public function get x():Number {
  2.     return super.x;
  3. }
  4. override public function set x(value:Number):void {
  5.     super.x = value;
  6. }

For now you can debug only properties (getters and setters), and types that are String, Number, Boolean (and color).

Here is a list of component that can be used.

Actionscript:
  1. BinderUI.displayLabel(this, s, "x")
  2. BinderUI.displayColorChooser(this, sprite, "color", 0xFFFF00);
  3. BinderUI.displayCheckBox(this, sprite, "halfTransparent", "half transparent");
  4. BinderUI.displayIndicatorLight(this, sprite, "halfTransparent", "half transparent");
  5. BinderUII.displayNumericStepper(this, sprite, "x", 5, null, 0, 900, 1);
  6. BinderUI.displayInput(this, sprite, "x");
  7. BinderUI.displaySliderHorizontal(this, sprite, "x", "x", null, 0.1, 1, 0, 900);
  8. BinderUI.displaySliderVertical(this, sprite, "x", "x", null, 0.1, 1, 0, 900);
  9. BinderUI.displayTextarea(this, sprite, "x");
  10. BinderUI.displayKnob(this, sprite, "x", "x", null, Knob.VERTICAL, 20, 0, 900);
  11. BinderUI.displayMeter(this, sprite, "x", "x", null, 0, 900);

In some case, it is harder to bind values, such as when you want to update a component from what you type in a textfield. You’ll need to dispatch an event yourself (usually these events are added by the compiler with the Bindable metadata tag).

Actionscript:
  1. dispatchEvent(new PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE, false, false, PropertyChangeEventKind.UPDATE, 'text', oldValue, newValue, this));

About colors, you can use the displayColorChooser method. The easiest is using a “color” property for example.

Actionscript:
  1. BinderUI.displayColorChooser(this, mySprite, "color");

You can also use the colorTransform property but this property is not bindable, so it will work only in one way (component —> target):

Actionscript:
  1. BinderUI.displayColorChooser(this, mySprite.transform, "color");

You can also use the MinimalConfigurator to create your interface from an XML file.

Three methods are available to dispose (remove and destroy) components. You can dispose by target, by component or dispose everything.

Actionscript:
  1. BinderUI.disposeByTarget(mySprite);
  2. BinderUI.disposeByComponent(myComponent)
  3. BinderUI.dispose();

Download source and demos.
Source on github.

Vote in HexoSearch

Comments No Comments »

I've updated SomaUI, the AIR tool that generates the draft of a Flash website build with SomaMVC. Sorry for the late update but you can now use the generator with Flex 4 and target the Flash Player 10.1.

To avoid a confusion, SomaUI is an AIR tool that generates AS3 sources build with the AS3 MVC Framework SomaMVC.

SomaMVC has nothing to do with SomaCore, they are 2 different frameworks and don't share the same goal.

While SomaMVC (which would entered in the same category as the Gaia Framework) is meant to be generated and rely on an XML File to describe and build its content, SomaCore is a lightweight MVC framework that doesn't build anything for you and would entered in the same category as PureMVC.

I intend at some point to rebuild SomaMVC using SomaCore and unify these 2 projects.

You can find the new SomaUI version on this page or on the Google code project.

Vote in HexoSearch

Comments 17 Comments »

Hi everyone,

In case you didn't notice that I released an new minimal AS3 MVC Framework some time ago, SomaCore is available on this page.

I call it minimal because it is very lightweight, yet powerful and non-intrusive. You don't have much to learn if you're used to MVC framework of any sort.

I made an update today, the second one in months because it won't change a lot, the structure is there. All the sources and demo have been updated.

You can also replace any kind of previous use of the framework, the only feature added is a dispose method that will remove everything that has been created in the framework. Mostly useful in case you're creating several instance of the framework, it will now be correctly garbage collected.

Once you've created a instance of the framework:

Actionscript:
  1. var app:ISoma = new Application(stage);

The only things you need to do is

Actionscript:
  1. app.dispose();
  2. app = null;

Here is what it is doing to the components that have been added to the frameworks:

- all wires will be removed. On each wire, the dispose method will be called. You can overwrite this dispose method in your wires subclasses.

- all models will be removed. On each model, the dispose method will be called. You can overwrite this dispose method in your models subclasses.

- all commands will be removed

- all views will be removed but not removed from the display list, that's your job. On each view, a dispose method will be called if it exists. You can create this dispose method in your views:

Actionscript:
  1. public function dispose():void {
  2.     // dispose objects, graphics and events listeners
  3. }

It important to say that all the components will be removed from the framework, but that's your matter to properly destroyed what you're creating in order to be garbage collected.

A quick info for my plans because I've silent lately (busy).

I'll make a BaseUI release in the next weeks, a completely rebuilt and optimized version 4. It is ready but I need to finish the documentation.

After that I plan to make more examples and screen cast about the SomaCore Framework.

I just wanted to say that I'm rarely happy about what I'm producing, because I like things to be... perfect. Of course, perfection can't be reached, but that is pushing me to create the better code I can, at my level.

I'm now using SomaCore in some projects. One is a relatively complicated AIR Modular Application for children. And for once, I'm very happy with what I've done with SomaCore. It has been a great help really, I should say that it saves me a lot of troubles when changes happened because I built the application how I wanted it, without "framework-fight" and as much flexible as I could. It just made me more responsive to any kind of changes in the project.

For this reason, I'll try to push SomaCore further by making more demos, videos, examples, documentation, wires concept and so on.

I still have plans to create a new version of the first automated framework Soma MVC, and its source generator, based on SomaCore.

Happy development!

Vote in HexoSearch

Comments 3 Comments »

I needed to watch objects to know if they were properly garbage collected or not, so I've added a GC Monitor in the SomaCore Debugger. It is pretty easy to use and I think very useful if you start to care about the memory that the Flash Player is using and global performance.

Demo Flash (garbage collection monitor)

SomaCore Flash AS3 Demo - Garbage Collection

View Demo
View Source
Download Source

The concept to use it is to "register" an object, such as a Sprite or anything, with a name.

The first step is to create the debugger. If you're using the framework SomaCore, you'll find some demo by clicking here.
And if you want to use the debugger without using SomaCore, here is a snippet to create the application and debugger:

Actionscript:
  1. package {
  2.     import flash.display.Sprite;
  3.     import com.soma.core.Soma;
  4.     import com.soma.core.interfaces.ISoma;
  5.     import com.soma.debugger.SomaDebugger;
  6.     import com.soma.debugger.vo.SomaDebuggerVO;
  7.     import com.soma.debugger.events.SomaDebuggerEvent;
  8.     public class Main extends Sprite {
  9.         function Main() {
  10.             // create soma application
  11.             var app:ISoma = new Soma(stage);
  12.             // create debugger options
  13.             var vo:SomaDebuggerVO = new SomaDebuggerVO(app, SomaDebugger.NAME_DEFAULT, [], true, false);
  14.             // create debugger
  15.             var debugger:SomaDebugger = app.createPlugin(SomaDebugger, vo) as SomaDebugger;
  16.             // use debugger
  17.             debug("Hello Debugger");
  18.             debug(this);
  19.             debug(app);
  20.         }
  21.         private function debug(obj:Object):void {
  22.             // use app.dispatchEvent() from a class that is not in the display list
  23.             dispatchEvent(new SomaDebuggerEvent(SomaDebuggerEvent.PRINT, obj));
  24.             // events available:
  25.             // SomaDebuggerEvent.SHOW_DEBUGGER;
  26.             // SomaDebuggerEvent.CLEAR;
  27.             // SomaDebuggerEvent.PRINT;
  28.             // SomaDebuggerEvent.HIDE_DEBUGGER;
  29.             // SomaDebuggerEvent.MOVE_TO_TOP;
  30.         }
  31.     }
  32. }

Register an object to watch it:

Actionscript:
  1. dispatchEvent(new SomaDebuggerGCEvent(SomaDebuggerGCEvent.ADD_WATCHER, "my sprite", mySprite));

You can dispatch this event from anywhere in an DisplayObject in the display list (Sprite, MovieClip, etc), from the document class, the stage or the SomaCore instance.

In the debugger window, there is a "garbage collection bar" where you can click to see the registered objects, they can be either "retained" or "released". A released object means it has been garbage collected and doesn't exist anymore. The memory used by this object will be free to use.

A "force" button will trigger the garbage collection, it will call System.gc() twice with a small interval. This should only works in a Flash Player Debugger version, but useful for debugging.

Here is a list of events you can use for the garbage collection monitor:

Actionscript:
  1. SomaDebuggerGCEvent.REMOVE_ALL_WATCHERS
  2. SomaDebuggerGCEvent.REMOVE_WATCHER // pass the name of he object as parameter
  3. SomaDebuggerGCEvent.ADD_WATCHER // pass the name of the objects and the object itself as parameter
  4. SomaDebuggerGCEvent.FORCE_GC

Note: by default SomaDebugger is now using a weak reference to the objects that you want to inspect. You can turn off this option to inspect everything in the debugger, but the objects will never be released, making the garbage collection monitor useless.

Here is how to force the inspection of any objects:

Actionscript:
  1. SomaDebugger.WEAK_REFERENCE = false;

Any feedback appreciated!

Romu

Vote in HexoSearch

Comments 3 Comments »