How to use AS3Navigator history for mobile (android etc.)

The problem i’ve been having has probably the most to do with my lack of the RobotLegs framework. I’ve been wanting to implement navigation history for a mobile app i’m making. I’m using the amazing AS3Navigator in combination with RobotLegs, which makes development a breeze as far as i’m concerned. However, i couldn’t find a simple way to enable navigation history management the way i wanted to. Thing is, when a user starts the mobile application, there is a preloader and a splash screen (2 views, 2 mediators). If the user starts the application for the first time, there’s a third screen after the splash screen (1 view, 1 mediator offcourse.) Still with me? Check out the amazing visual below i made to make this clear: (I will create this later ;p)

So, when a user starts navigating and doing stuff in the app, views change. When the user hits a soft (visual) back button on the iPhone, or the hard backbutton on an android device, the previous view should transition on screen (which happens perfectly through use of the NavigationHistory back(); method. However, i don’t want a user to be able to go back BEFORE the home screen! I’ve been messing around with this problem for a long time, even trying to make a special historyModel which is offcourse bullcrap, but i wasn’t seeing the simple solution below:

Have a ‘GoBackCommand’ extend ‘SignalCommand’ or ‘Command’ if you don’t use SignalCommands (from the robotlegs signal extension library -> … )

Have at least this in your variable definitions:

[Inject] public var history : NavigatorHistory;

Have these simple lines in your overridden execute method:

override public function execute():void {

if( !history.back() ){

// androids will exit the app, iPhones will suck and do nothing until user closes application

//NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);

NativeApplication.nativeApplication.exit();

}

Explanation: history.back() without arguments supplied will go back 1 step in history. That is, if there is a step to go back to. We can use this to our advantage. What if the last step to be ABLE to go back to, was the home screen? Then, we could do something like this:

if( history.back() ) {

// we don’t neccesarily have to do something here, if the return value for history.back() is true (which it is, if there’s history to go back to. check out this function if you don’t understand this)

} else {

// quit app, since there is no more history to go back to (we are at the home screen)

}

But, offcourse, we can also negate the return value of this function, so we will not need the else clause. Which we did in the first piece of code, by adding an exclamation mark in front of the function: !history.back().

Okay, having done that, we now have to make sure our home screen, or first, initial screen, is the first history state. how do we do this? simply by clearing the navigation history in each mediator of the screens that come before the homescreen!

Which can be done with:

history.clearHistory();

So, put this line in your initialize() function of each mediator that comes before your homescreen like so:

public function initialize():void

{

// reset history

history.clearHistory();

}

It’s as simple as that! Good luck dev’ing!

What the heck are AIR Native Extensions?

The quick explanation

With we released of AIR 3.0 we added this awesome new feature called native extensions. Trust me these are cool. Essentially, a native extension will let you extend the functionality of your AIR app so it can access the native capabilities of a device. So, by adding some native code you can:

  • make a mobile device vibrate.
  • change the channel on a TV
  • read pressure sensitivity data from a pen table
The more technical explanation

A native extension is a combination of:

  • ActionScript classes.
  • Native code. Native code is defined here as code that executes outside the runtime. For example, code that you write in C is native code.

Here’s why you might want to write your own extension:

  • A native code implementation provides access to device-specific features. These device-specific features are not available in the built-in ActionScript classes, and are not possible to implement using application-specific ActionScript classes. The native code implementation can provide such functionality because it has access to device-specific hardware and software.
  • A native code implementation can sometimes be faster than an implementation that uses only ActionScript.
  • A native code implementation allows you to reuse existing code.

When you have finished your ActionScript and native implementations, you package your extension. Then, an AIR application developer can use the package to call your extension’s ActionScript APIs to execute device-specific functionality. The extension runs in the same process as the AIR application.

An even more technical explanation

Here’s an architectural diagram of an extension:

Where to get extensions

Because you can package and reuse extensions, you don’t need to write one yourself. You can use someone else’s. We’ve even set up a handy page where you can find some extensions to get you started. These extension were contributed by both our in-house dev team and our community. Take a look.

If you’re interested in creating your own extension, we’ve created a whole set of content just for you. Check out the Native extensions doc here.

16 Useful mathematics formulas in AS3

http://ntt.cc/2010/07/06/16-useful-mathematical-formulas-in-actionscript-3.html

1. Distance Between Two Points


dx = x2 – x1;
dy = y2 – y1;
dist = Math.sqrt(dx*dx + dy*dy);

2. Inching Formulas


sprite.x += (targetX – sprite.x) * easing;//easing: inching coefficient
sprite.y += (targetY – sprite.y) * easing;

3. Elastic Formulas


vx += (targetX – sprite.x) * spring; //spring: elastic coefficient
vy += (targetY – sprite.y) * spring;
sprite.x += (vx *= friction); //friction: friction force
sprite.y += (vy *= friction);

4. Flexible Partial Shifts Formulas


var dx:Number = sprite.x – fixedX;
var dy:Number = sprite.y – fixedY;
var angle:Number = Math.atan2(dy, dx);
var targetX:Number = fixedX + Math.cos(angle) * springLength;
var targetY:Number = fixedX + Math.sin(angle) * springLength;

5. Rotation With Mouse Formulas


dx = mouseX – sprite.x;
dy = mouseY – sprite.y;
sprite.rotation = Math.atan2(dy, dx) * 180 / Math.PI;

6. Waveform Formulas


public function onEnterFrame1(event:Event):void {
ball.y=centerScale+Math.sin(angle)*range;
angle+=speed;
}

7. Heartthrob Formulas


public function onEnterFrame1(event:Event):void {
ball.scaleX=centerScale+Math.sin(angle)*range;
ball.scaleY=centerScale+Math.sin(angle)*range;
angle+=speed;
}

8. Circle Rotation Formulas


public function onEnterFrame(event:Event):void {
ball.x=centerX+Math.cos(angle)*radius;
ball.y=centerY+Math.sin(angle)*radius;
angle+=speed;
}

9. Get Circle Area


public function getArea():Number
{
// The formula is Pi times the radius squared.
return Math.PI * Math.pow((width / 2), 2);
}

10. Get Circumference Ratio


public function getCircumference():Number
{
// The formula is Pi times the diameter.
return Math.PI * width;
}

11. Elliptic Rotation Formulas


public function onEnterFrame(event:Event):void {
ball.x=centerX+Math.cos(angle)*radiusX;
ball.y=centerY+Math.sin(angle)*radiusY;
angle+=speed;
}

12. Color operations


var t:uint=0×77ff8877
var s:uint=0xff000000
var h:uint=t&s
var m:uint=h»>24
trace(m);

13. Hex to Decimal


trace(hexValue);

14. Decimal to Hex


decimalValue.toString(16);

15. Pick Up Color


red = color24 » 16;
green = color24 » 8 & 0xFF;
blue = color24 & 0xFF;
alpha = color32 » 24;
red = color32 » 16 & 0xFF;
green = color32 » 8 & 0xFF;
blue = color232 & 0xFF;

16. Color Bit Arithmetic


color24 = red « 16 | green « 8 | blue;
color32 = alpha « 24 | red « 16 | green « 8 | blue;

We're about to code some virtual bubble wrap in my ActionScript class.

My life just got infinitely more exciting.

Introducing Starling

 

image

Starling is an ActionScript 3 2D framework developed on top of the Stage3D APIs (available on desktop in Flash Player 11 and Adobe AIR 3). Starling is mainly designed for game development, but could be used for many other use cases. Starling makes it possible to write fast GPU accelerated applications without having to touch the low-level Stage3D APIs. 

Подробнее на bytearray.org
Официальная страница книги на O’Reilly
Прямая ссылка на книгу

Crocus UML Modeller for Actionscript

Flash and Actionscript developers tend to be very good at UML modelling, mainly because over the years we have always had to do it in our heads. We have never had a fit for purpose UML modelling tool before, I personally used to make all my UML’s using something like mockflow, so they were pretty rushed and crappy.

We remember Grant Skinner having something similar to a UML application for AS2, but it faded away as we moved into AS3 development in 2006 and was never replaced.

With Flash being used less and less for small projects where HTML5 is replacing it, UML is becoming very important for large ActionScript software projects, it is such a time saver. Putting in that little bit of extra time at the start of a project is really worth it; because you save so much time not having to go back through code and refactoring everything when you realise you haven’t planned fully as a development team.

Our saviour is here! We are starting to use the Crocus UML tool and from what we have seen so far it looks incredible!

It does so much for you to get a project started:

It models all of your packages, classes and Interfaces with properties and methods, and maps class relationships. It supports pretty much any coding style you have, even if you use MXML. Once your UML model is complete it will export your stub files for you so you can code directly into the stubs, all laid out in the right place.

It does loads of other things besides and really does appear to be ridiculously fully featured for what is essentially an indy app. We can’t wait to trial it fully on a new project soon.



Loading more posts...