If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Regular expressions are something that were introduced in AS3 with a sigh of relief from all flash developers. Yay
Below is a code snippet posted by senocular at kriupa
function isValidEmail(email:String):Boolean { var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(email);
}
//...
trace(isValidEmail("senocular@example.com")); // true
trace(isValidEmail("@example.com")); // false
trace(isValidEmail("senocular@example")); // false
trace(isValidEmail("seno\\cular@example.com")); // false
Its a beautiful thing.
Found this useful? How about buying me a coffee - simply click here.
The SimpleButton class is a sweet way to put sprites together to make a button. The SimpleButton is a light weight alternative to the heavier MovieClip object.
var myButton:SimpleButton = new SimpleButton();
myButton.upState = mySprite1;
myButton.overState = mySprite2;
myButton.downState = mySprite3;
myButton.hitAreaState = mySprite4;
You can also draw your sprites on the fly.
var myButton:SimpleButton = new SimpleButton();
//create the look of the states
var down:Sprite = new Sprite();
down.graphics.lineStyle(1, 0x000000);
down.graphics.beginFill(0xFFCC00);
down.graphics.drawRect(10, 10, 100, 30);
var up:Sprite = new Sprite();
up.graphics.lineStyle(1, 0x000000);
up.graphics.beginFill(0x0099FF);
up.graphics.drawRect(10, 10, 100, 30);
var over:Sprite = new Sprite();
over.graphics.lineStyle(1, 0x000000);
over.graphics.beginFill(0x9966FF);
over.graphics.drawRect(10, 10, 100, 30);
// assign the sprites
myButton.upState = up;
myButton.overState = over;
myButton.downState = down;
myButton.hitTestState = up;
Found this useful? How about buying me a coffee - simply click here.
I previous of flash there was no way to detect when the users mouse had left the flash movie.
Actionscript 3 now allows you to detect when the users mouse has left the movie using the mouseLeave event.
Lets take a look:
package {
import flash.events.Event;
import flash.events.MouseEvent;
public class mouseLeaveTest extends Sprite {
public function mouseLeaveTest() {
stage.addEventListener(Event.MOUSE_LEAVE, mouseHasLeft);
}
public function mouseHasLeft)(e:Event):void {
trace('Mouse have left the stage');
}
}
}
Found this useful? How about buying me a coffee - simply click here.
ActionScript 3.0 is a powerful object-oriented language that represents a new programming model for the Flash Player runtime. If you are already familiar with ActionScript 1.0 or 2.0, you should be aware of some language differences as you develop your first application using ActionScript 3.0.
To help the transition adobe has compiled tips and common issues you might encounter during development.
http://www.adobe.com/devnet/actionscript/articles/actionscript_tips.html
Found this useful? How about buying me a coffee - simply click here.
This is a simple but effective function allows you to search a string and replace characters
function searchAndReplace(holder:String, searchfor:String, replacement:String) {
var temparray:Array = new Array();
temparray = holder.split(searchfor);
holder = temparray.join(replacement);
return (holder);
}
Found this useful? How about buying me a coffee - simply click here.
One of the pimping new features of AS3 is the ability to label your loops. At first you may think this is pointless but once you start using them you will find out how wonderful they truly are.
They come into their own when you have nested loop structure and you want to exit loops when a certain condition is met.
Kudos goes to senocular for me finding out about this cool feature.
In AS2 you would do the following to break a loop.
var i:Number;
var j:Number;
var exit:Boolean = false;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
if (i > 3 && j > 3) {
exit = true;
break;
}
}
if (exit) {
break;
}
}
But with AS3 and labels you can break from a specific loop.
E.G
var i:Number;
var j:Number;
mainLoop: for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
if (i > 3 && j > 3) {
break mainLoop;
}
}
}
With labels the nested loop is able to break the mainloop. This makes the code cleaner and easier to read.
Nice.
Found this useful? How about buying me a coffee - simply click here.