Entries Tagged 'actionscript' ↓
12th May 2009 — actionscript
Lets set the scene: your lazy. You got a sweet a design in photoshop and now you need to bring it to life in flash. Now remember your lazy so your going to use flash’s PSD importer to import the layers into flash. What a timer saver. Flash has has made movieclips and text layers from the photoshop layers, nice. You hookup some functions and publish the file. But something is wrong, some the text looks a little fuzzy and some of the lines are little blurred. You jump back to the fla and check through some of the movieclips. Bah, flash has placed some clips in-between pixels. You’ve even got the ‘Snap to Pixels’ feature turned on but flash has ignored when doing the import.
This has happened to me countless times and often on a big flash project it can be real drag digging through movieclips trying to find the elusive off-pixel clip. It would great I thought if I had a little pixel pixie to go through my FLA and fix up all the movieclips and textfields. Well I couldn’t find any pixies or elfs that where willing to work for me so instead I wrote recursive function to do it at runtime.
This script takes in one argument, the base movieclip it then goes through every child of that movieclip and rounds the x and y position to the nearest pixel. So that every stage instance is rendered on a whole pixel. If any of these clips have children if goes through them and rounds their position and so on and so on recursively until it does each movieclip, sprite or textfield in the swf.
roundChildren(this)
function roundChildren(base:DisplayObjectContainer):void {
for (var i:int=0; i<base.numChildren-1; i++) {
var m:DisplayObject=base.getChildAt(i) as DisplayObject;
var p:DisplayObjectContainer=base.getChildAt(i) as DisplayObjectContainer;
if (m) {
m.x=Math.round(m.x);
m.y=Math.round(m.y);
if(p){
if (p.numChildren>0) {
roundChildren(p);
}
}
}
}
}
Checkout the example below to see the script in action. The pixel snapping does not effect dynamic text because of the way flash anti-aliases it. But you can see a big improvement for the static text and vector lines placed inside a movieclip.
This movie requires Flash Player 10
2nd April 2009 — actionscript
SWFAddress is the amazingly easy to use solution for deep linking in flash. Once setup its simply a case of calling SWFAddress.setValue("myfolder") to change the browser location bar and using SWFAddress.getValue()to get the current url when SWFAddressEvent.CHANGE is triggered.
In fact SWFAddress is so simple to use that when something goes wrong it hard to find the problem because there are no options to change. The difficulty I ran into recently was when I upgraded to the latest version 2.2 For an inexplicable reason, swfaddress’s SWFAddressEvent.CHANGE would no longer trigger.
I finally isolated the issue to how you include the swfaddress & swfobject javascripts in your html. The order of includes is extremely important. Swfobject must be included before swfaddress, if you using swffit add this after swfaddress. Also you must add a flash id to swfobject’s attributes for embedding. Check out the example below for for SWFAddress 2.2, SWFObject 2 and swffit harmony.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="swfaddress.js"></script>
<script type="text/javascript" src="swffit.js"></script>
<script type="text/javascript">
var flashvars = {};
var params = {};
var attributes = {id:'mainswf'};
swfobject.embedSWF("main.swf", "container", "100%", "100%", "9.0.115","expressInstall.swf", flashvars, params, attributes);
swffit.fit("mainswf", 960, 580);
</script>
</head>
<body>
<div id="container">
</div>
</body>
</html>
28th March 2009 — actionscript
If your anything like me use you use the trace statement feverishly when developing a flash project, the trace output is the available within the flash IDE and debugging is a straightfoward process. The problem I have found with using trace for debugging is when you move the project into a browser environment. I frequently find that the swf functions slightly different or there are bugs which cause the swf to silently die. There is however a great solution for viewing the trace statements from the browser.
First you’ll need to download and install flash debugger flash player 10 debugger.
Create a file named “mm.cfg” ( if it does not exist) in one of the following locations:
- Windows;
C:Documents and Settingsusernamemm.cfg
- OSX;
/Library/Application Support/Macromedia/mm.cfg
- Linux;
home/username/mm.cfg
Open the newly created mm.cfg file in a text editor and add the following text:
ErrorReportingEnable=1
TraceOutputFileEnable=1
Reboot your machine.
Browser debugging should be now enabled. All trace statements from any swf will be outputted to the file /Users/[username]/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt
Open a flash site, then look at the file and you’ll see all the traces coming from the swf.
Personally I find opening this file each time annoying so I use the tail -f command from the terminal so I can follow the file and see live trace outputs.
tail -f /Users/phil/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt
Check this blog for an explanation the technique customised for windows.
20th November 2008 — actionscript

This is an example of how to use the actionscript displacement filter and bitmapData to create a sliding water droplet effect.
example here
actionscript 3 source here
16th September 2008 — actionscript

I’ve been playing around with latest version of Papervision. I found this great tutorial on how to load Collada mesh models. Here is a little swf I mashed up. It uses 2 collada models but groups them together as one object with actionscript. Tweener is used to control the animation and mouse events. You view the AS source and DAE model files here.
This movie requires Flash Player 10
6th September 2008 — actionscript

(flash + skateboarding) * 3D = awesomeness
Checkout this awesome little flash game built on papervision 3D. Its a very simple idea but pretty effective, lets hope he keeps the development going and takes it to the next stage. If I was this dude, I’d try and market the idea to Tech Deck.