Firefox 3.6 introduced a very annoying bug, and only on a Mac.

If you're using somewhere a MouseEvent.ROLL_OUT or MouseEvent.MOUSE_OUT, this event will fired even if you only click on a object without leave the object with the mouse.

Example there

The select box in the middle of the page doesn't work because a roll out event is fired when you click on it.

I didn't try yet to find a fix with MOUSE_UP and MOUSE_DOWN, but the problem is, all the existing sites that are using those events might be broken...

I believe Firefox is, or not firing the right event, or removing and putting back the flash so it loses the focus, meaning roll out is fired... A friend told me that the same things happen with java applet, didn't verify it yet.

Bug report

To test it, paste this as a document class:

Actionscript:
  1. package com.soundstep.baseui.demo {
  2.     import flash.events.MouseEvent;
  3.     import flash.display.Sprite;
  4.     public class Main extends Sprite {
  5.         public function Main() {
  6.         var s:Sprite = new Sprite();
  7.         s.graphics.beginFill(0xFF0000);
  8.         s.graphics.drawRect(0, 0, 100, 100);
  9.         s.addEventListener(MouseEvent.MOUSE_OUT, test);
  10.         addChild(s);
  11.         }
  12.         private function test(e:MouseEvent):void {
  13.             trace("ok");
  14.         }
  15.     }
  16. }

Click on the square and you'll see that the MOUSE_OUT is fired...

I hope they'll fix soon or I'll have to find a hack and change everything that is live.

Romu

Vote in HexoSearch

Comments 10 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 »

I've updated the debugger used in SomaCore. You can know click on everything to parse the objects and I've added a FPS + Memory meter. I'll continue to improve the debugger with my needs, next step might be a Garbage Collection monitor.

Click here to see the debugger in action.

Tips: if you close the debugger, type "debug" to get it back.

Here is a little bit of code in case you want to want to use the debugger without using the SomaCore Framework.

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

Vote in HexoSearch

Comments No Comments »

Following my previous post about MVC design philosophy and an AS3 MVC Framework that suit my needs and expectations, I've started using SomaCore in a relatively complicated AIR modular application, and I'm really enjoying it.

I made some small changes to the code and I thought it would be a good idea to provide you the sources. SomaCore was a missing tool in my actionscript work.

I've started to feel the power of the native Flash event system (even if criticized!) by being able to listen to commands independently of the commands itself (and what the command is doing), or being able to "preventDefault" any command, or to monitor very easily everything that is going on in the framework. The wires have been a good help to keep my code very clean without tons of classes, while keeping my models and views completely free of framework code.

I also found out some kind of hidden capabilities I didn't think about while making it. One of them is an "easy module communication", so easy that, you have absolutely nothing to do to enable it. When I say module, it could be another SomaCore instance, a loaded SWF, another SomaCore instance in a loaded SWF, and so on. But I'll give more details later.

You can now find the (updated) SomaCore resources on the SomaCore Page.

Special thanks to Henry for his testing and feedback!

Feel free to use the sources and give me some feedback. I'll try later to give more explanation on how to use SomaCore and the Wires, new demos and tutorials.

Romu

Vote in HexoSearch

Comments 1 Comment »

Hi Everyone,

This is not exactly a "Soma release", but I would like to share with you my last work so we can talk about: A new AS3 MVC Framework with its own design philosophy.

Why another AS3 MVC Framework?

I've been working with different Frameworks in the last years, such as PureMVC, Cairngorm and Mate for the well-known. I've always knew that I would write my own "MVC design philosophy", without taking big words, because I would have some needs that existing Frameworks wouldn't completely fill.

That's what happened. I needed a Flash lightweight framework, not DI, event based, working both for Flex or Pure AS3. The biggest inspirations have been PureMVC for the proxies and mediators, and Mate for their event system.

I'll be starting an interesting AIR Modular app and I needed something that will easily allow me to have views and models free of Framework code, without creating tons of files or use any injection. I also wanted a Framework very flexible, so I can use it even for smaller project, being sure I'll be effective in terms of development time.

Free the views and models

First problem, free the views and models of Framework code (loose-coupling). It seems there's a wave of DI Framework but... I've never really been into DI Framework, because they tend to control the way you're doing things. If you stick to it, it is fine, but I've always felt more freedom with framework like PureMVC. I might be wrong, it is just an opinion and not even entirely true as I didn't felt that problem with Mate.

So, to solve this problem, I used the events Mate concept. A basic Flash Events that has a bubble property set to true can become Commands when they are mapped to a Command class. Those events can be intercepted, stopped and processed by the Framework (execute Commands). The great thing is, views and models are free of Framework code and can use Commands because they are just Flash native events.

Wires introduction

Second problem, was to "update" data or states in the views and models. PureMVC is using proxies and mediators and I like that approach. However, you end up by creating tons of files for the sake of loose-coupling pratice. So I've created something that I call "Wire". Now software engineers or PureMVC adept might say that what I'm doing is wrong. I have no idea, I'm no computer scientist, I do what I feel and I'm sharing it with you.

Wire are classes that can contain Framework code and they will be the links between the models, the views, the Framework and... whatever you like. Wire can be proxies, they can be mediators, but they can also be both and handle more than one view or model.

Basically, they are as free as you want them to be. They can even be optional if you don't care about good practice or loose-coupling programming. Wires have easy access to all the framework, models, commands and views. They can register create models, views, register commands or create other wires.

Update from comment:

So far I saw two ways to inject/update information into views without having framework code inside:

- Dependency Injection
- Buffer classes (such as Mediators and Proxies in PureMVC for the analogy, respectively for Views and Models). I mean "buffer" by classes that act as steward of other classes.

I've chosen the second way, and I've created a "buffer" class that I called a Wire.

Wires are completely free classes. I won't tell you how to use them (because that's up to you) but I can tell what you can do with them. Wires can be used to update views and models but they are not tight to anything. They are not even only tight to one tier. To create a wire class you extend Wire and implements IWire, and here are the roles they can take:

- a wire can act as steward of a view (such as Mediator in PureMVC)
- a wire can act as steward of a model (such as Proxies in PureMVC)
- a wire can manage both a view and a model
- a wire can manage multiple views and/or multiple models
- a wire can be considered as a subdivision of the framework and create its own views, create its own models and register its own commands. Much like you would create a specific package to hold a specific matter.

When I build something, I always try to keep a good level of freedom to handle problems how I like but most importantly, how they should be. If you like to have the framework telling you (or forcing you) how to build your application, fair enough but you won't like it.

The wires are the free elements that will let you built your application the way you like or the way it is required to be. They can make your application rigid, segmented, flexible or centralized, depending of the role you are going to give them. They are so free that I believe remove (or lesser) what I call "Framework Fight".

Let's take an example, the Cafe TownSend below.

There are 2 wires: the LoginWire and the Employee Wire. They both register their own commands to control their views and models.

The Login Wire only handles a Login View.

The EmployeeWire handles 2 views: a list of employees and an employee details. But also 1 model (the employees data), all of them only related to employees matter.

SomaCore

I temporarily named this framework SomaCore and it has nothing to do with the Framework I released on this blog (Soma). However, this framework might become the core of what will be Soma v3.

I post this code hoping to get your feedback or point of view of what might be great or wrong in this framework.

Here is a diagram:

SomaCore MVC Diagram


Click here to download a zip file containing the Framework sources code (classes and SWC).

And here are some demos. I made a Flex Cafe TownSend demo and a pure AS3 demo.

SomaCore Flex Cafe TownSend SomaCore Flash AS3 Demo
View Demo
View Source
Download Source
View Demo
View Source
Download Source

This is a very early state, this Framework has not been used yet in a real project beside the demos above. Have a look and please comment what you feel is good or wrong in the core concept.

Romu

Vote in HexoSearch

Comments 10 Comments »