Archive for the ‘AS3’ Category
Dear Mr. Jobs (a personal response from a flash developer to Section 3.3.1)
This is reply to Apples change of rules for iPhone developers:
To be honest, I never really liked Apple products. I always liked the design, but not the restrictions and the disciples.
When the company I worked for gave all employees an iphone I was very sceptical. But it turned out that I got very used to this gadget that really does feel very nice. Apart from the fact that it was the end of me listening to music outside, because iTunes tried to take all life out of my PC, I enjoyed playing around with it and surfing the web.
Also the concept of the Appstore seemed amazing to me. An opportunity to sell small programs to a worldwide group of iPhone-users with not too many restrictions sounded better the more I thought about it.
Despite being a flash-developer, I considered looking into Objective-C, but simply up to now did not have the time to do so. Obviously it was great news for me when Adobe announced the iPhone-compiler for the upcoming Flash CS5 last year. Ever since that news I had been looking forward to this release…
As you well know, three days before the release you changed the rules, making all the work Adobe put into this feature pretty much worthless. To many this felt like a slap in the face of Adobe. Sitting aside, watching someone else work and getting their hopes up, just to crush all hope in the very last stage. This reminds me of a big slow kid in the playground that destroys the sand-castles of the other kids when they’re almost done.
But this is not only a slap in the face of Adobe, it is a slap in the face of all flash developers. So this is my reply to your actions: F*** you Mr. Jobs! Or in the words of Lee Brimelow: “Go screw yourself Apple”
Rotate dynamic system fonts with Flash Player 9
Using Flash player 10 lets us use the rotationZ paramter of a TextField. But of course some clients require us actionscript developers to support the older player version as well.
An easy way to get around this problem is to draw the TextField into a Bitmap. I use my own TextUtils class with a static method like this:
public static function convertTextFieldToBitmap(textField : TextField) : Bitmap
{
var bitmapData : BitmapData = new BitmapData(textField.width, textField.height, true, 0×00000000);
bitmapData.draw(textField);
var bitmap : Bitmap = new Bitmap(bitmapData);
bitmap.smoothing = true;
return bitmap;
}
So rotating and fading the TextField is no problem anymore, also the scaling works much smoother:
AS3 + JavaScript = Resizable SWF in HTML
I recently needed to resize an swf dynamically within an HTML document and could decided to combine JavaScript with AS3. So here is my solution in three simple steps:
- I wrote a simple JavaScript file that allows resizing of elements in an animated fashion.
- I embedded the swf in the HTML file in a <div> container with the style attribute “overflow:hidden;” and an id called “swf_container”.
- To ensure the desired effect I added stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT;
- Now I added a button in the Flash file that caused navigateToURL(new URLRequest(”JavaScript:sizeById(’swf_container’,500,150,5)”), “_self”); and with this calling the JavaScript function and resizing itself.
If you want to try this yourself you can download the JavaScript file sizebyid.js and recreate what I did with it or download the whole sample.zip including the -.Fla, the -.swf, the -.js and the -.html file.
Of course you can try it out first:
Click the arrow in the top left corner to toggle sizes of the sample.
You can also use the following html form that calls the same JavaScript function
A simple Magnifying Class for AS3
It has been a while that I first programmed a magnifier glass in Actionscrtip 2. But since several friends asked over time how to do it I rewrote it in AS 3.
You can download the entire class for free here: magnify.as
There are no license attachments whatsoever. So you can modify it, reuse it, sell it, whatever you like. But of course I would like to receive some feedback. You can also place links in the comments here to your site if you used this class.
The main important part is the following calculation:
_mc_mask.x=mouseX;
_mc_mask.y=mouseY;
_loaderMc.x=(-_loaderMc2.mouseX)+_loaderMc2.mouseX/_scaleRatio;
_loaderMc.y=(-_loaderMc2.mouseY)+_loaderMc2.mouseY/_scaleRatio;
First the image is loaded twice and then it positions the image that is only partially visible in the right spot over the smaller image so that it seems to be the same image.
To include the class in your own project all you need to is:
- unzip bjornson.zip into the same directory your FLA-file is in
- write code similar to this in your actions dialogue of your FLA (this is the very minimum you need):
- import bjornson.Magnify.Magnify;
var m:Magnify = new Magnify(”a.jpg”); //this should be a relative path to a .jpg or .png
addChild(m); - Publish the file, done!
- scr:String - this is the relative path to your image
- w:Number - this is the maximum width of the preview image
- h:Number - this is the maximum height of the preview image (it will be adjusted automatically to fit while keeping the correct aspect ratio)
- s:Boolean - this is to switch from a rectangular magnifier to a round magnifier
- r:Number - this is the radius of a round magnifier or the height of a rectangular magnifier
- rw:Number - this is the width of a rectangular magnifier
- m:Boolean - this defines if the Mouse-Pointer is visible when it moves over the image or not
