Technologies
- Flash, CSS, AS3
Brief
- Created @radical.media for Tommy Hilfiger
- Live Site
Role
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
- Flash, CSS, AS3
- Created @radical.media for Tommy Hilfiger
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
ul>
- Flash, CSS, AS3
- Created @radical.media for Tommy Hilfiger
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
- Flash, XML, AS3
- Created at Marvel Entertainment
- Jr. Flash Developer - Translate AS2 to AS3
- Made use of a Tweening Engine
- Receive XML and send Requests via PHP
- Flash, CSS, AS3
- Created @radical.media for Tommy Hilfiger
- Jr. Flash Developer - Create the page Template
- Made use of a Tweening Engine
- Flash, CSS, AS3
- Created @radical.media for Viacom
- Jr. Flash Developer - Help style the CSS, animated logo, and minor AS3/AS2 Flash work
I’ve gotten a lot of positive feedback on the Cool Flash Tip of the Week series. So as long as people find them useful, I’ll keep them coming. Make sure to subscribe to be on top of all tips and add me on twitter. Now with all the formalities out the way, lets get a move on to the tip of the week. This week’s tip is about Events!!
I’m sure you are wondering, what kind of tips can you not know already. Events are a big topic in Actionscript 3.0. Almost everything is based on event listeners and is event driven. During my time coding, I found a couple of handy shortcuts that made my day easier. Let’s say you have a simple event handler that adds a MovieClip to the stage when a link is clicked. For simplicity’s sake , lets pretend we have a MovieClip in the library named “myMC”, and a button on the stage called “myLink”.
myLink.addEventListener(MouseEvent.CLICK, addClip);
function addClip(e:MouseEvent):void
{
stage.addChild(myClip);
}
This would be the typical way we would do it. This is absolutely correct, but what if we wanted in a different function to add the clip as well. Some one would probably try to execute that this way.
myLink.addEventListener(MouseEvent.CLICK, addClip);
otherFunction();
function addClip(e:MouseEvent):void
{
stage.addChild(myClip);
}
function otherFunction():void
{
stage.addChild(myClip);
}
Although this is correct, the ideal way to program is to reuse code as much as possible so that when its time to update you caan change the code in one spot and it will update throughout the program. Not to mention it cleans up the code considerably. A better alternative to this would be to call addClip(). But WAIT!!, this is an event handler, if I call this I get an Argument Error. This is true, but we can setup the event handler to be an event listener and also be called without needing an event. Here is how we acheive that.
myLink.addEventListener(MouseEvent.CLICK, addClip);
addClip();
function addClip(e:MouseEvent = null):void
{
stage.addChild(myClip);
}
//------------------OR--------------------
myLink.addEventListener(MouseEvent.CLICK, addClip);
addClip(null);
function addClip(e:MouseEvent):void
{
stage.addChild(myClip);
}
That was pretty simple now was it. I use this all the time in my code to shorten things up and clean my code. I do prefer to the first method than the second alternative. I rather not have to keep passing null than just setting the default to null instead. Keep in mind, that this will only work if you do not need the actual event in your functions logic. If you do, then you need to an event. Well that’s all for this week’s tip. I hope you found it useful in any sense. Next week will be a big week, so stay tuned and subscribe to the feed.
I’m going to start a series that will occur every week. A cool flash tip or something I think not many people know about. Be on the lookout every week for a new tip. This week’s CFT is ……drumroll…….” The Tertiary Operator “.
I spend alot of time traversing flash posts looking at other peoples code and I often see a large if else block to change a simple variable. Using the Tertiary Operator we can simplify this into one line of code. Shorter code is always better in my opinion. Plus can save you a couple bytes in your code.
Here is an example of what I see.
var myBool:Boolean = false;
var myVar:Number = 12;
if(myBool == true)
{
myVar = 15;
}
else if(myBool == false && myVar == 10)
{
myVar = 40;
}
else
{
myVar = 0;
}
Now this is all well and dandy, but it is a waste of space and can be simplified by a lot. One, when testing a Boolean there is no need to test to true or false. Instead if you want to test if something is true, you can just place the variable in the if parenthesis. This will automatically test to true. To test if a variable is false, use !. Here is an example.
var myBool:Boolean = false;
var myVar:Number = 12;
if(myBool )
{
myVar = 15;
}
else if(!myBool && myVar == 10)
{
myVar = 40;
}
else
{
myVar = 0;
}
This already shortens up our code a bit. But we can take this a step further using the Tertiary Operator. The syntax for this is pretty simple once you know what it means.
//Tertiary Syntax
(Test) ? True : False;
Basically, If the test is true, the code after the ? executes. If the test is false the code after the : executes.
You can also string together Tertiary statements to make and if else if else etc. Here’s how we write the same code from above over using the Tertiary Operator.
var myBool:Boolean = false;
var myVar:Number = 12;
myVar = (myBool ) ? 15 : (!myBool && myVar == 10) ? 40 : 0;
WOW, look how much space we saved, and it i still readable. I implore everyone to start using this and save space =D. Be aware that it is advised no to string Tertiary statements past “If..Else”. If you liked this idea of CFT ( Cool Flash Tip ), then leave a comment, subscribe to the feed or / and follow me on twitter. It would be great to get some feedback on if this is helpful or not and maybe some tips you would like to see featured here.
Happy Flashing
- Actionscript 3.0, XML
- Nice, advanced audio player with simple controls.
- Actionscript 3.0, XML
- Simple and clean banner / image rotator. XML driven slide show which supports links and loads JPEGS , PNGS, GIFS and SWFS .
Finding a good Flash Blog as a developer is sometimes hard to find. Here are a couple that I keep stashed in my RSS Reader.
This is an excellent blog of experiments and cool effects that you can do in Flash. Some of the popular posts on this blog include an ASCII Art Generator that turns images AND videos into ASCII characters.
Another great experimental blog that is heavily concentrated on 3d and particles.
A very informative blog and home to the FlashCamo Decal framework. I call The Flash Art of War a developer’s view in laymen terms. Make sure if you are in the NYC area to check out NYC Flash Developers Happy Hour.
Stay on top of everything Flash from Platform Evangelist Lee Brimelow. Make sure to check out gotoAndLearn and browse through the excellent screencasts.
Great resource for learning what you can do with ByteArrays and all sorts of techniques that are hard to find around the web.
Excellent resource about memory and cpu management involving the Flash Player. Also home to the retired but popular gTween Tweening Engine.
Great resource for programing in Actionscript 3.0. This blog usually has tons of information on open source API’s and popular topics like Augmented Reality, Flash Player 10 3D and much more