By scott
As I mentioned in my presentation on Tuesday at 360 Flex pipes.yahoo.com have launched a wide open crossdomain file today. Flash Community rejoice! This is huge news for us. Not only does it mean we can load in manipulated aggregated data feeds, it also means we can load in feeds that normally we do not have access to because there is no crossdomain policy. Before you could do this with a php or any server side based page proxy file. But now you don’t have to worry about that. Log in to pipes, do a simple fetch, save it, and load in your pipe through pipes.yahooapis.com. Simple! If needed, you can manipulate the feed, remove unnecessary data and output it. No one wants to parse irrelevant data, especially client side! As some have already said, pipes is the future of the Internet and if we didn’t know it already flash is too!
One last thing, if you want to learn more about using pipes, there is a great video tutorial up on the Yahoo! Developer Network.
Thanks a lot pipes from the entire flash development community.
By scott
Just came across a great article on Actionscript development using Eclipse and the FDT Plug-in. http://www.actionscript.com/Article/tabid/54/ArticleID/Optimizing-Your-Workflow-with-Eclipse-and-FDT/Default.aspx
I have been an actionscript developer for a long time and have been using SEPY for good portion of that time, but recently I found myself on the hunt for a new editor. Nothing against SEPY, the newest release (Nov 3 I think) is very solid, and he finally got the tabs working properly (other than the removal of the right click menu to close a tab).
I also tried JEdit, it was good, some cool features just found there wasn’t a lot of AS support out there. And everything seemed a bit dated.
Eclipse on the other hand has tons of features/plug-ins, heck, it’s what Flex Builder is built off of so there is already tons of interest in this IDE from the community. Another great plug-in and a necessity if you plan on using Eclipse for your development is ASDT:
http://sourceforge.net/projects/aseclipseplugin/
This plugin adds in all the things we’re used to from other IDE’s, coloring, code collapsing, code completion, etc.
And lastly, the other cool thing is hooking up Eclipse to MTASC for real time error checking. Check this article for instructions on installing MTASC with Eclipse. Both cool and frustrating to see all your errors on the fly. Much better than hitting CTRL-enter and seeing 9000 errors because you spelled Boolean wrong.
I find IDE’s are like your favourite pair of pants and it is hard to part with one because you are so comfortable in them. However, one day when you rip the ass out of them you find that a new pair isn’t a bad thing and helps you with the ladies. OK, Eclipse won’t help you with the ladies but you know what I mean, or do you?
By scott
In Flash Player 8 a lot of the work I have done on the Rolex suite of sites has worked fine, once the Flash Player 9 update came out we noticed some very mysterious Javascript errors and only in IE on a PC. The error was very undescriptive, Syntax Error Line 53. The other odd thing was nothing broke, all of the javascript was executed, and all of the actionscript was executed. We were simply doing a call down to a javascript that executed some tracking and analytics calls. It was a very basic ExternalInterface.call method call. We even commented out everything else in the Actionscript and Javascript functions. We still saw the error. Using Microsofts script debugger we discovered that the javascript error is in the Javascript that the Flash player appends to parent.window, this javascript is used in the communication between flash and the browser.
I put a call into Adobe/Macromedia support and they confirmed it is a bug in Flash Player 9 and will be fixed in the next release. Unfortunately they couldn’t tell me when the next player will be released. This bug isn’t documented on the Flash Player 9 bug page, however another strange and unrelated bug is. If you have a hyphen in the your swf file name ExternalInfterface communication will not work. I hope this is not a sign of what is to come with the Adobe future.
Let me know if anyone else has run into this issue.
By scott
People don’t always realize that the Macromedia Tween Classes does more than just move MovieClips or fade MovieClips in and out. I wish I got a nickel for everytime I heard someone say I didn’t know you could do “that” with the Tween class. Most people do not realize you can tween filters (blur, dropshadow, glows, bevel, etc). And even more people don’t realize you can use the tween class to control volume on a sound object or change the font size of a text field. Basically you can blur any property. Here is an example of text being blured via the tween class.
import flash.filters.BlurFilter;
import mx.transitions.easing.Regular;
import mx.transitions.Tween;
var template_mc:MovieClip = this;
var textHolder:MovieClip = template_mc.createEmptyMovieClip('textHolder_mc',
template_mc.getNextHighestDepth());
var tf:TextFormat = new TextFormat();
tf.font = '_serif';
tf.color = 0x000000;
tf.size = 18;
textHolder.createTextField('text_txt', 1, 0, 0, 200, 50);
textHolder.text_txt.text = 'This is my device font uber blur test';
textHolder.text_txt.autoSize = 'left';
textHolder.text_txt.setTextFormat(tf);
textHolder._x = (Stage.width/2) - (textHolder._width/2);
textHolder._y = (Stage.height/2) - (textHolder._height/2);
var blurText = new Tween(textHolder, "blur", Regular.easeOut, 0, 16, 3, true);
blurText.onMotionChanged = function(ev:Object) {
ev.obj.filters = [new BlurFilter(ev.obj.blur, ev.obj.blur, 3)];
}
blurText.onMotionFinished = function() {
this.yoyo();
}
Here is an example using the tween class to change the font size of a text field.
import flash.filters.BlurFilter;
import mx.transitions.easing.Elastic;
import mx.transitions.Tween;
var template_mc:MovieClip = this;
var textHolder:MovieClip = template_mc.createEmptyMovieClip('textHolder_mc',
template_mc.getNextHighestDepth());
var tf:TextFormat = new TextFormat();
tf.font = '_serif';
tf.color = 0x000000;
tf.size = 18;
textHolder.createTextField('text_txt', 1, 0, 0, 200, 50);
textHolder.text_txt.text = 'This is my device font test uber size test';
textHolder.text_txt.autoSize = 'center';
textHolder.text_txt.setTextFormat(tf);
textHolder._x = (Stage.width/2) - (textHolder._width/2);
textHolder._y = (Stage.height/2) - (textHolder._height/2);
var stretchText = new Tween(textHolder.text_txt, "size", Elastic.easeOut, 18, 75, 2, true);
stretchText.onMotionChanged = function(ev:Object) {
var newSize = Math.round(ev._pos);
var tf:TextFormat = new TextFormat();
tf.size = newSize;
ev.obj.setTextFormat(tf);
}
stretchText.onMotionFinished = function() {
this.yoyo();
}
Any numeric value can be “tweened”, try it out yourself, it is a very useful class.
By scott
I only posted the AS 3.0 Make it Rain effect yesterday and I have been bombarded with people asking me to release the source. It’s not the tightest code yet but here it is anyway:
package {
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.filters.ConvolutionFilter;
import flash.geom.ColorTransform;
import flash.filters.DisplacementMapFilter;
import flash.utils.Timer;
import flash.events.TimerEvent;
class RainMaker {
private var __scope:MovieClip;
private var __clip:MovieClip;
private var __sourceBitmap:BitmapData;
private var __bitmap1:BitmapData;
private var __bitmap2:BitmapData;
private var __buffer:BitmapData;
private var __outputImage:BitmapData;
private var __bounds:Rectangle;
private var __origin:Point;
private var __matrix:Matrix;
private var __matrix2:Matrix;
private var __wave:ConvolutionFilter;
private var __damp:ColorTransform;
private var __water:DisplacementMapFilter;
private var __surface:BitmapData;
private var __fillcolour:int = 128;
private var __xPos:int;
private var __yPos:int;
private var __lastx:int;
private var __lasty:int;
//Movieclips
private var cloneClip_mc:MovieClip;
function RainMaker(scope:MovieClip, clip:MovieClip) {
__scope = scope;
__clip = clip;
draw();
}
private function draw():void {
cloneClip_mc = new MovieClip();
__scope.addChild(cloneClip_mc);
var bitmapImage:BitmapData = new BitmapData(__clip.width, __clip.height, false, 0);
bitmapImage.draw(__clip);
__surface = bitmapImage;
__clip.visible = false;
__bitmap1 = new BitmapData(__clip.width, __clip.height, false, __fillcolour);
__bitmap2 = new BitmapData(__clip.width, __clip.height, false, __fillcolour);
__sourceBitmap = new BitmapData(__clip.width, __clip.height, false, __fillcolour);
__buffer = new BitmapData(__clip.width, __clip.height, false, __fillcolour);
__outputImage = new BitmapData(__clip.width, __clip.height, true, __fillcolour);
__bounds = new Rectangle(0, 0, __clip.width, __clip.height);
__origin = new Point();
__matrix = new Matrix();
__matrix2 = new Matrix();
__matrix2.a = __matrix2.d = 2;
__wave = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 1, 1, 1, 1, 1], 9, 0);
__damp = new ColorTransform(0, 0, 0.99609374, 1, 0, 0, 2, 0);
__water = new DisplacementMapFilter(__bitmap2, __origin, 4, 4, 32, 32, "ignore");
var bm:Bitmap=new Bitmap(__outputImage);
cloneClip_mc.addChild(bm);
var __waterTimer:Timer = new Timer(10);
__waterTimer.addEventListener('timer', turnOnWater);
__waterTimer.start();
var myTimer:Timer = new Timer(150);
myTimer.addEventListener('timer', waterEffect);
myTimer.start();
}
private function fitsArea():Boolean {
var curX = __xPos;
var curY = __yPos;
if ((curX < __clip.width) && (curY < __clip.height)) {
return true;
} else {
return false;
}
}
private function waterEffect(ev:Object):void {
if (isNaN(__xPos)) {
__xPos = 0;
__yPos = 0;
} else {
if (fitsArea()) {
__xPos = Math.random()*__clip.width;
__yPos = Math.random()*__clip.height;
} else {
__xPos = 0;
__yPos = 0;
}
}
__lastx = __xPos;
__lasty = __yPos;
}
private function turnOnWater(ev:Object):void {
var curX = __xPos / 2;
var curY = __yPos / 2;
if ((__lasty != curY) || (__lastx != curX)) {
__sourceBitmap.setPixel(curX + 1, curY, 16777215);
__sourceBitmap.setPixel(curX - 1, curY, 16777215);
__sourceBitmap.setPixel(curX, curY + 1, 16777215);
__sourceBitmap.setPixel(curX, curY - 1, 16777215);
__sourceBitmap.setPixel(curX, curY, 16777215);
}
__lastx = curX;
__lasty = curY;
__bitmap1.applyFilter(__sourceBitmap, __bounds, __origin, __wave);
__bitmap1.draw(__bitmap1, __matrix, null, "add");
__bitmap1.draw(__buffer, __matrix, null, "difference");
__bitmap1.draw(__bitmap1, __matrix, __damp);
__bitmap2.draw(__bitmap1, __matrix2, null, null, null, true);
__outputImage.applyFilter(__surface, new Rectangle(0, 0, __clip.width,
__clip.height), __origin, __water);
__buffer = __sourceBitmap;
__sourceBitmap = __bitmap1.clone();
}
}
}
By scott
In my quest to make things more difficult for myself and roll my own blog using php, sql, and my flash CMS, I have finally finished the comments functionality. Not bad for a Flash Developer
Let me know what you think.
By scott
One of the complaints I often hear about is keeping scope when using controls and/or event listeners. One of my favourite classes is the Delegate class. This class ensures scope is kept by allowing you to specify the scope when calling a method. For example:
import mx.utils.Delegate;
class Whatever extends MovieClip {
private var someClip_mc:MovieClip;
function Whatever() {
someClip_mc.onRelease = Delegate.create(this, someMethod);
}
private function someMethod():Void {
trace(this);
//this will return a reference to the movieclip that is
//attached to the Whatever class and not someClip_mc
}
}
Ok, that’s all fine and dandy, now what if you need to pass a paramater to the method you’re targeting. You could extend the Delegate class and allow for this, or you could write your own class that does the same thing but allows for paramaters to be passed. But really, who has time to do that! Below is the same example as above but this time I pass a paramater to the method.
import mx.utils.Delegate;
class Whatever extends MovieClip {
private var someClip_mc:MovieClip;
function Whatever() {
var myDel = someClip_mc.onRelease = Delegate.create(this, someMethod);
myDel.button = someClip_mc;
myDel.index = 4;
}
private function someMethod():Void {
var button:MovieClip = arguments.caller.button;
var index:Number = arguments.caller.index;
trace(button + ' has an index of ' + index);
//this will trace out someClip_mc has an index of 4
}
}
Now you may be wondering where the heck you would use this. Picture this, you are building a menu system from an xml document. You create buttons dynamically based on the amount of data, all buttons call the same method but the method needs to know what button was selected so it can set its selected state and it also needs to know the content id associated to the button selected so the appropriate content is loaded. Instead of having a seperate method for each content id/button or updating your code everytime the data is updated this allows you to write a completely dynamic menu system in the least amount of code.
Like I said above, this isn’t the best solution, but it is a solution to the fact the Macromedia forgot to add in the ability to pass an object along to the method being called. Good news is scope is not an issue in AS 3 so the Delegate class isn’t even needed.