Friday, June 4, 2010
Saturday, May 15, 2010
Embedding Fonts into Actionscript Only Project (AS3)
[Embed(source='/assets/calibri.ttf', fontName="
Calibri",
// TextFormat object
mimeType="application/x-font-truetype")]
private static var _calibri:String;
var format :TextFormat = new TextFormat();
format.font = "Calibri"; // Here is where the magic happens
format.color = 0xffffff;
format.size = 12;
// TextField object
var txt :TextField = new TextField();
txt.embedFonts = true;
txt.antiAliasType = flash.text.AntiAliasType.ADVANCED;
txt.defaultTextFormat = format;
txt.text = "Testing my embedded Calibri font";
addChild(txt);
Basically, we need to understand a couple things about the nature of
the embedded font in Actionscript. First, it must be assigned to a
String in order to store all the character references. Next, you will
quickly find that creating and implementing a TextFormat object to
attach the font and styles to the different places in which it will be
used is ideal. Finally, keep in mind that attaching several fonts to a
single application can significantly increase the file size, so try to
consolidate and style for variety as much as possible instead of
selecting a boat load of different font faces.
Friday, May 14, 2010
Bitmap.smoothing - how to reduce image distortion
Saturday, May 8, 2010
Robotlegs Flex site Tutorial
RobotLegs is a light-weight, pure AS3 micro architecture created by Shaun Smith. It provides a
mechanism for writing your Objects in a decoupled way. And it provides an automated metadata based
mechanism of Dependency Injection. It has lot of similarities in pureMVC and has features like dependency
injection.
Using Robotlegs
using Flex4
Download Robotlegs swc form link
Add to your project
RobotLegsFlex Document class
It creates an instance of ApplicationContext class
ApplicationContext class
The ApplicationContext class extends the Context. The Context lies in the heart of a Robotlegs
implementation, providing the mechanism by which the implementation’s tiers will communicate. The
Context provides three functions within an application: initialization, de-initialization, and creates the central
event bus for communication. Although an application is not limited to a single Context, for many use cases
one Context is sufficient.
The ApplicationContext class extends the base context class in the Robotlegs framework. Its constructor accepts an instance of the RobotLegsFlex document class which is assigned to the variable contextView and is accessible on throughout the application.
In Robotlegs implementation we typically override the startup() method to set up all the mappings for dependency injection, views and events. Here we map a Singleton of SiteModel and an instance of SiteDataService which implements ISiteDataServive interface to the Injector . This makes them available to the other classes the application via the [Inject] metadata. We then map 3 view classes (BasePage, LoginPage and HomePage) to their respective mediator by calling the mapView method of MediatorMap instance. A mediator provides a bridge between the framework and the viewComponent it is responsible for. It passes along framework events to its view component and sends framework events in response to events dispatched by its view component. By putting application-specific logic in the mediator we decouple the view components fro the application’s implementation.
Finally we call the mapEvent method of commandMap instance to map events to their respective commands. The ContextEvent.STARTUP_COMPLETE is dispatched by the framework upon completing the execution of Context’s startup() method. Here we map BasePage command to handle this event.
BasePage Command Class
The BasePage Command class extends the command. As intended by the command mapping the BasePage command class responds to the context’s STARTUP_COMPLETE event. In BasePage Command class we add BasePage view Component to the contextView.. The contextView in the command is a DisplayObjectContainer , and be can’t use it directly to add children to it. So we can add like this.
BasePage.mxml
The BasePage viewComponent contains two stack elements LoginPage viewComponet and HomePage viewComponet. In RobotLegs the mappings in the MediatorMap as shown in ApplicationContext allows a mediator to be automatically created when its respective viewComponet is instantiated.
BasePageMediator
The BasePageMediator class extends the mediator class in the RobotLegs framework.. Typically, one take advantage of onRegister() handler which is invoked when the Mediator has been registered with the framework, to perform set up tasks on the viewComponent and map events with their event handlers.. Here we invoke mapListener method of eventMap instance to map SiteDateService.LOGIN_SUCCESS framework event to its respective event handler.
In this class we access the BasePage singleton via the [Inject] metadata and assign It to the basePage variable. The onLoginSuccess() responds to the SiteDataService.LOGIN_SUCCESS and change the stack index in the BasePage.
LoginPage.mxml
Upon clicking the send button it dispached a UserEvent with type- CHECK_LOGIN and data- login details.
LoginPageMediator
Here we access the LoginPage and ISiteDataService via the [Inject] metadata. In onRegister() we invoke mapListener method of EventMap instance to map LoginPage.CHECK_LOGIN UserEvent to corresponding event listener checkLogin(). In this method we call the checkLogin function in the SiteDataService class and passing data as arguments.
SiteDataService class
In Robotlegs, the Model and Service classes extends the base Actor class to inherit the functionality for communication with the framework. A Model encapsulates and provides an API for data and sends event notifications when the data model has been changed. A Service communicate with the outside world through web services or file access and dispatches system events in response to external events.
In SiteDataService class, we access SiteModel singleton via the [Inject]metadata and assign it to the model varable. In checkLogin function it updates the username and password in the sitemodel and dispatched an event with type LOGIN_SUCCESS. The Basepage mediator listen to this event. And when this event occurs/dispatched the stack index in the BasePage is changed to 1(HomePage).
HomePageMediator
In HomePageMediator we access the SiteModel singleton and HomePage via the [Inject] metadata and assign ito the model and homePage variable respectively. In the onRegister method username text field In HomePage is updated with the value in siteModel class.