Ever need a class, view more about but can’t remember if it is in the flash, pills mx or spark package, see even drilling down further, was it in data, net or utils? There are so many classes in so many locations there is no way to remember them all or the properties and methods associated with them.

A quick tip I use often is typing “new”, then tapping the space bar. If code hints are working, the code hint window will appear listing all the possible classes. Typing the first and even second letter of the class name will filter the list, once you select the class you are looking for, that class will automatically be imported at the top of the file, if it’s needed.

This works almost anywhere and on any class, even static. I use it when I don’t feel like typing out long class names like StageDisplayState or TextFieldAutoSize. Type “new [space] stag” then click on the correct class. Boom!, it’s imported and completely typed out for you.

For a quick reference to which properties and methods are available in the class, remove the word “new” from before the class name that was just selected, then type a “.” right after the class name. This produces another code hint menu listing the public properties and methods.

Code hinting will also import classes automatically when a colon is added after a variable name, but just typing “new” and a space, is indeed the fastest.

Just remember to remove the new [Class] you just used to trigger the code hint window, if you forget, the compiler will let you know.


Ever need a class, order but can’t remember if it is in the flash, mx or spark package, even drilling down further, was it in data, net or utils? There are so many classes in so many locations there is no way to remember them all or the properties and methods associated with them.

A quick tip I use often is typing “new”, then tapping the space bar. If code hints are working, the code hint window will appear listing all the possible classes. Typing the first and even second letter of the class name will filter the list, once you select the class you are looking for, that class will automatically be imported at the top of the file, if it’s needed.

This works almost anywhere and on any class, even static. I use it when I don’t feel like typing out long class names like StageDisplayState or TextFieldAutoSize. Type “new [space] stag” then click on the correct class. Boom!, it’s imported and completely typed out for you.

For a quick reference to which properties and methods are available in the class, remove the word “new” from before the class name that was just selected, then type a “.” right after the class name. This produces another code hint menu listing the public properties and methods.

Code hinting will also import classes automatically when a colon is added after a variable name, but just typing “new” and a space, is indeed the fastest.

Just remember to remove the new [Class] you just used to trigger the code hint window, if you forget, the compiler will let you know.




Ever need a class, viagra buy but can’t remember if it is in the flash, mx or spark package, even drilling down further, was it in data, net or utils? There are so many classes in so many locations there is no way to remember them all or the properties and methods associated with them.

A quick tip I use often is typing “new”, then tapping the space bar. If code hints are working, the code hint window will appear listing all the possible classes. Typing the first and even second letter of the class name will filter the list, once you select the class you are looking for, that class will automatically be imported at the top of the file, if it’s needed.

This works almost anywhere and on any class, even static. I use it when I don’t feel like typing out long class names like StageDisplayState or TextFieldAutoSize. Type “new [space] stag” then click on the correct class. Boom!, it’s imported and completely typed out for you.

For a quick reference to which properties and methods are available in the class, remove the word “new” from before the class name that was just selected, then type a “.” right after the class name. This produces another code hint menu listing the public properties and methods.

Code hinting will also import classes automatically when a colon is added after a variable name, but just typing “new” and a space, is indeed the fastest.

Just remember to remove the new [Class] you just used to trigger the code hint window, if you forget, the compiler will let you know.




This tips does not recognize HTML tags within the Label Spark component, information pills only parsing the actual text out of HTML content or converting HTML entities so they show up as normal text in the Label component.

Recently I had to localize an application that used Spark TextArea and Label components. All the text content was contained in xml files and the chinese translation was encoded as HTML entities. Here is how we were able to get all the characters to show up properly in our Spark Labels.

Add a TextArea to the stage that will act as an HTML entity converter.
This tutorial is the third part in a series on game development with AS3. We will pick up where we left of in the last tutorial which can be found here: ActionScript 3 101 : Game Development part 2

In the previous tutorial we made a MovieClip of a ball move back and forth by pressing the left and right arrow keys on the keyboard. We accomplished this through the use of a variables, pill functions and events. In this tutorial we will continue to modify our existing code by adding a couple new functions and create something that will begin to resemble an actual game.

The Swap:
The first thing we need to do and swap out the ball artwork with a spaceship graphic. The graphic included with the source is the same dimensions as the ball, which was 72 x 72 pixels. You can use the one in the source code below ( just copy it into your project and delete the ball) or build your own.




The Stage:
To get everything ready for this round of edits, we need to rearrange a few things and increase the size the of the stage.The new size for the stage will be 600 x 600 pixels. To complete the space theme, a black background is required, later we can add a star field and possibly a nebula to make it look really cool, but for now a solid black background will be sufficient.



For the final visual update, please move the spaceship near the bottom center of the stage so it looks like it’s ready to attach something.



Updating the Code:
The visual updates we have just completed require modifications to the existing actionScript to keeps things functioning correctly. Click on the first frame of the actions layer to make the updates in the Actions Panel.

1. Find and Replace “ball” with “ship”.
With the visual change from ball to ship, we should update our code to match. It’s not a necessity, but will help in understanding our code going forward. Use Find and Replace to replace the string “ball” with “ship” in the Actions panel.



This will also require an update to the name of the ball instance on the stage, from “ball” to “ship” in the Properties Panel.



2. The Stage is now wider, updating the “boundsRight” variable will allow the spaceship to move all the way to the new width.

?View Code ACTIONSCRIPT
// right x of the stage
var boundsRight:Number = 505;

3. Updating the position of the ship requires an update to the “moveX” variable, now the ship’s movement starts from the ship’s current position.

?View Code ACTIONSCRIPT
// the current x position of the ball.
var moveX:Number = ship.x;

Let’s test what we have. The functionality is the same, but man does it look cool.


Get Adobe Flash player


If your version does not look or function like this demo, please go back over the previous steps to make sure nothing was skipped.

Even More Cool:
With a bit more code and using the foundation we’ve already created, we can make this ship fire plasma projectiles. Now we’re talkin’!

Plasma Projectiles:
The included ship has two guns, one on each wing, so we will be demoing shooting two plasma balls at a time. Feel free to make up your own gun configurations and deviate from this tutorial as much as you feel comfortable.

Let’s create the graphics, these plasma balls were made from a blue radial gradient. #09B1FF with 100% alpha in the center and #027BD6 with 0% alpha at the edge. A little highlight circle was added as well as, a little rim light at the bottom to give it depth. #95E9F3 with 65% alpha for the highlight and #5F91FA with 30% alpha for the rim.



Not actual size

If your shapes that make up the plasma balls are drawing objects (not broken all the way down) then you can easily duplicate and slide over a copy. Otherwise you may need to group all your shapes before making the duplicate.

The last step is to make the plasma balls longer than tall, the oval shape looks a little better when in motion.

Convert the plasma balls into a symbol, a MovieClip named “ShipBomb” to be exact. While you are in the Convert to Symbol dialog box, select the Export for ActionScript check box. You can do this later by accessing the MovieClips properties in the library if needed.

When you click OK, you should receive the following “class could not be found…” message. This is Fine, click OK and continue. We will get into classes more in the next tutorial, but for now, this message is telling us that there is not an external class found to be associated with this new class, so Flash will just create the new class as is.



A MovieClip is a class, and ShipBomb is a class that extends the functionality of MovieClip, so now we can use this with our actionScript.



Making Plasma Fly:
Inside the ShipBomb MovieClip, we will add the following actionScript in the Actions Panel.

1. Importing the Event class, this should should automatically when you add the frameHandler function below, but only if you type it out, if you copy and paste, you will have to add it manually.

?View Code ACTIONSCRIPT
import flash.events.Event;

Tip: Learn more more tips importing classes in Flash and Flash Builder.

2. Create two new variables:

?View Code ACTIONSCRIPT
// To which y coordinate the bomb should travel?
var minY:Number = 0;
 
// How fast should the bomb travel?
<pre lang="actionscript">
var speed:Number = 10;

3. Create an event handler for the enter frame event.

?View Code ACTIONSCRIPT
function frameHandler(ev:Event):void{
 
// On every frame decrease the y position by the amount of speed, moving this upward.
this.y -= speed;
 
// If the y position is less the the minimum y coordinate, clean up and remove itself.
if(this.y < minY){
this.removeEventListener(Event.ENTER_FRAME, frameHandler);
this.parent.removeChild(this);
}
}

4. Add the event listener

?View Code ACTIONSCRIPT
this.addEventListener(Event.ENTER_FRAME, frameHandler);

If the ShipBomb MovieClip is still on the stage, try a quick test, it should move up the screen and disappear.
After the test, please remove the instance of ShipBomb from the stage.

Controlling the Weapon:
Adding in the previous code was not so bad and finishing things up will be just as easy.

1. Create a function in the root of the fla. On the actions layer, first frame, enter the following code into the Actions Panel.

?View Code ACTIONSCRIPT
// ship fires bomb
function fireBomb():void{
 
// create a new instance of ShipBomb
var bomb:ShipBomb = new ShipBomb();
 
// set the bombs y position equal to the ships y position.
bomb.y = ship.y;
 
// set the bombs x position equal to the ships x position, plus 10,
// to align the plasma balls to the guns.
bomb.x = ship.x + 10;
 
// cache the bomb as a bitmap to help performance.
bomb.cacheAsBitmap = true;
 
// add the bomb to the stage
addChild(bomb);
}

2. The keyboard events are already being handled by the function called keyHandler. A few tweaks and additions to this function and we will have a ship that fires.

?View Code ACTIONSCRIPT
// if the key is up and that key is the same as the currently pressed key
// ignore the key press if it is the space bar, or keyCode 32.
if(!keyPressed && currentKey == ev.keyCode && ev.keyCode != 32){
 
//stop movement
moveXKeyDown = false;
return;
}

3. Down, near the end of the keyHandler function add the following conditional and call to the fireBomb function.

?View Code ACTIONSCRIPT
// if the key is pressed and it is the spacebar, fire the bomb.
if(keyPressed && ev.keyCode == 32){
fireBomb();
}

Now do a test to see what we have.


Get Adobe Flash player


Hopefully your version works very similar to this sample. You may want to tweak the x or y starting position of the bomb to make sure it is aligned properly.

Download the Source code here.

Complete Code:
The SpaceGame Fla frame 1:

?View Code ACTIONSCRIPT
import flash.events.KeyboardEvent;
 
/** CONFIG **/
 
// left x of the stage
var boundsLeft:Number = 20;
 
// right x of the stage
var boundsRight:Number = 505;
 
// base speed or distance to move the ship
var maxSpeed:Number = 10;
 
/** RUNTIME VAIRABLES **/
 
// how far the ship travels each frame
var speed = maxSpeed;
 
// the current x position of the ship.
var moveX:Number = ship.x;
 
// the keyboard is pressed
var moveXKeyDown:Boolean;
 
// which keyCode is currently down.
var currentKey:int;
 
/** EVENT HANDLERS **/
 
// Enter Frame Event handler
function frameHandler(ev:Event):void{
 
if(moveXKeyDown){
// increase the ship x position by the value of speed
moveX += speed;
 
// if ship x reaches right bounds
if(moveX >= boundsRight){
// stop movement
moveXKeyDown = false;
//  set the ship x position to the right bounds
moveX = boundsRight;
}
 
// if ship x reaches left bounds
if(moveX <= boundsLeft){
// stop movement
moveXKeyDown = false;
// set the ship x position to the left bounds
moveX = boundsLeft;
}
 
// update the ship's x property to equal moveX
ship.x = moveX;
}
 
}
 
// handle keyboard key presses
function keyHandler(ev:KeyboardEvent):void{
 
// set moveVariable true or false depending on the keyboardEvent type
var keyPressed:Boolean = ev.type == KeyboardEvent.KEY_DOWN;
 
// if the key is up and that key is the same as the currently pressed key
if(!keyPressed && currentKey == ev.keyCode && ev.keyCode != 32){
 
//stop movement
moveXKeyDown = false;
return;
}
 
// which key was pressed and is it a key down
if(ev.keyCode == 37 && keyPressed){
// left arrow key down - move left
 
// set speed to negitive
speed = -maxSpeed;
 
// set current key code
currentKey = ev.keyCode;
 
// start move
moveXKeyDown = true;
}
 
if(ev.keyCode == 39 && keyPressed){
// right arrow key - move right
 
// set speed to positive
speed = maxSpeed;
 
// set current key code
currentKey = ev.keyCode;
 
// start move
moveXKeyDown = true;
}
 
if(keyPressed && ev.keyCode == 32){
fireBomb();
}
 
}
 
// ship fires bomb
function fireBomb():void{
 
// create a new instance of ShipBomb
var bomb:ShipBomb = new ShipBomb();
 
// set the bombs y position equal to the ships y position.
bomb.y = ship.y;
 
// set the bombs x position equal to the ships x position, plus 10,
// to align the plasma balls to the guns.
bomb.x = ship.x + 10;
 
// cache the bomb as a bitmap to help performance.
bomb.cacheAsBitmap = true;
 
// add the bomb to the stage
addChild(bomb);
}
 
/** EVENT LISTENERS **/
 
// setup event listener for the ENTER_FRAME event type
// point the event to trigger the "frameHandler" funciton above
addEventListener(Event.ENTER_FRAME, frameHandler);
 
// setup event listeners for the KEY_DOWN and KEY_UP types of the KeyboardEvent
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyHandler);
 
 
// stop this timeline
stop();

ShipBomb MovieClip frame 1:

?View Code ACTIONSCRIPT
import flash.events.Event;
 
var minY:Number = 0;				// To which y coordinate the bomb should travel?
var speed:Number = 10;				// How fast should the bomb travel?
 
function frameHandler(ev:Event):void{
 
// On every frame decrease the y position by the amount of speed, moving this upward.
this.y -= speed;
 
// If the y position is less than the minimum y coordinate, clean up and remove itself.
if(this.y < minY){
this.removeEventListener(Event.ENTER_FRAME, frameHandler);
this.parent.removeChild(this);
}
 
}
 
// add enter frame event listener
this.addEventListener(Event.ENTER_FRAME, frameHandler);
 
stop();

Where To Go From Here?
We have covered the basics in both code and logic for making things move and controlling these objects with the keyboard. See how for you can go with figuring out how to add bombs falling from the top of the screen. In the next tutorial we will go over classes and create some aliens for us to shot at. They will be shooting back at us.



Get as far as you can, work through the problems and see what you come up with. There are no wrong answers as long as it works.

For final source code which includes alien bombs falling, click here.

Another thing to do is mess with the Frame Rate of the Fla, see what kind of performance you can get. An Adjustment to the speed variables may be required to get things working just so. Most action games shot for 60 frames per second.

According to CNET, side effects there were about 1.2 billion mobile broadband subscriptions in 2011, adiposity mobile computing is quickly becoming the primary computing platform. As a developer, see mobile is an exciting place to be and the technology and landscape is changing every day. So what do we make of products like Google TV?

With so many companies trying to shoehorn every possible online service onto a tiny screen, do we really need to think about a technology that is stuck in one place, where people spend very little time these days? Web TV came and went in the 90s, with little success at bringing web services to the sofa; but, is cramming everything into a mobile device the right way to go either?

Mobile Technology is the Key
The latest mobile craze is the iPhone 4s and it’s virtual, all knowing personal assistant named Siri. Speak a question into the iPhone and Siri will respond with a humorous quip or the required answer. This is revolutionary. No longer must we stop what we are doing to fumble with a virtual keyboard, searching for information in a tiny web browser, a past email or map application. With all the efforts spent in the development of search engines, user interfaces and these remarkable computing devices, there has never been a more efficient way of obtaining information, then asking a simple question and receiving a simple verbal answer.

The Makings of the Smart Home
Making the TV the hub of our digital world could be be short sided. With the technology currently available, we could create a home that resembles those depicted in Sci-fi movies and TV shows, such as, Minority Report and Eureka. The smart home will be a growing trend 2012 and so far most solutions are focused on turning on and off lights and adjusting the thermostat from your phone, like a glorified clapper. The real destiny of the smart home is to become the new personal, home based, headless computer.

Apple computer currently sells Time Capsule a home backup server and wireless router. This device uses an application on your desktop or laptop called Time Machine to connect to Time Capsule, once contacted your computer is backed up over wifi. Imagine if Time Capsule was expanded to connect and backup our phones and tablets.

Note: With a Jail Broken iPhone, you can backup and restore your iPhone directly from Time Capsule, without the need for a laptop.

Besides backups, Time Capsule is also a router, which could trigger events when your cell phone makes a new connection. This would allow Time Capsule or other devices to know when we are at home and when our phone was away from home and out of range.

The Welcome Home App
After a long day, we arrive home, Time Capsule gives the iPhone an ip address and starts to backup. Siri says, “Welcome Home”.

There are many ways to accomplish this functionality without Apple products, but this is a demonstration of how close one company is to providing the ultimate Smart Home experience.

If we arrive home, Siri welcomes us, she knows it is pizza night because it is on our calendar, so the TV turns on (because we have Apple TV, now with Safari) displaying the menu and number to the local pizza joint. We say, “Call Ray’s Pizza” and pizza is ordered. Siri also knows that with our pizza we like to watch a family movie with the kids, so Apple TV then displays recommendations based on our video history. Again, all we have to do is say, “Play Movie” and we are watching our family movie.

After the kids are in bed, Siri could inform us on new episodes of our favorite TV shows.

Now lets expand things a little further with a few wireless cameras containing speakers and mics. If Siri were built into a new device, like the Apple TV, most likely called iHome or Apple Home, we could interact with Siri, our virtual assistant, anywhere in the house. Now add the electronic locks, light switches and thermostat, we now have an amazing smart home.

Could this be the next boom for Apple? Just think if Apple added takeout restaurant apps with in-app-purcahse to the iTunes store which allowed them to get a piece of every takeout order. That may be over the top, but really, Apple has the technology and products that are so close to making this a possibility and set the standard of this industry form the beginning. The biggest plus would be the price to setup the home would be so much more consumable.

The Pieces to the Perfect Smart Home:
1. A Siri API, to allow developers to create new apps that can be controlled by Siri, for building voice controlled Smart Homes and other lifestyle applications.

2. A common protocol for cameras, lights, locks, doors and thermostats. Sometimes Apple likes to build their own which would be sad.

3. An advanced router that allows all these devices to talk together.

4. An iPhone, iPad, mini PC or new Smart Home command center device with Siri.

5. Voice recognition for security and user accounts. Settings could be assigned to each individual in the family. With good voice recognition, Siri could control individual accounts based on voice.

How close is Microsoft to something like this?
With the xBox as the new hub and their partnership with Verizon which relies on the Fios router, they could have connections with Verizon Fios’ Home Control service. This service allows you to lock doors, turn off lights, adjust thermostats and monitor home security from anywhere. Without a Siri type virtual assistant, Microsoft or Verizon, just doesn’t have the complete package. Microsoft’s focus on just the TV, could leave them playing catch up again, as they have with smart phones, mp3 players, and tablets.

Google is working on a Siri type assistant for their mobile Android software that could prove to be great competition to Apple. Without any home-based devices on the market besides Google TV, they would need to develop a router to connect all smart home pieces together as Verizon does and Apple could. They have proven very capable at moving swiftly into a market they see potential in; and with plenty of partnerships with 3rd party device manufactures in love with Android, you may be seeing many non-mobile devices coming out running Android this year.

Amazon is a company that has made some great decisions lately, where they end up could be surprising. They provide top tier web hosting and cloud services, a huge retail machine, and a video/entertainment service. Amazon would have a lot to gain by getting into the smart home market. They have a large infrastructure, similar to google, to be a contender. Imagine light bulbs being automatically shipped from an Amazon vender when a light bulb burns out. Even if they wanted to take a back seat to the Smart Home revolution, all the hardware to setup these smart houses will most likely be purchased through Amazon anyway.

There will be a day when the home itself becomes the new personal computer and hub to our digital world.

If you already have a Smart Home, tell us how you did it.

Technorati Tags: , , , , , ,

Leave a Reply