Using lineStyle to draw stroke without affecting the size of the holder container
Have you ever tried to use the graphics class to draw a rectangle with a lineStyle (stroke) and then set bigger width and height values for the container that holds the graphic? If so, you probably noticed that there is a size difference between a rectangle with lineStyle and a rectangle without lineStyle.
If you trace the width and height values of the container, everything seems to be fine. Only if you run and look at the SWF you’ll notice a visual difference between those two (Image below)

ActionScript Code:
import flash.display.Sprite;
var rectangle:Sprite = new Sprite();
var rectangleLineStyle:Sprite = new Sprite();
with(rectangle)
{
graphics.beginFill(0x333333);
graphics.drawRect(0,0,50,50);
graphics.endFill();
}
with(rectangleLineStyle)
{
graphics.beginFill(0xd5e7ed);
graphics.lineStyle(3, 0xff0000, 1, false, LineScaleMode.NONE);
graphics.drawRect(0,0,50,50);
graphics.endFill();
}
addChild(rectangle);
addChild(rectangleLineStyle);
rectangle.width = rectangle.height = 200;
rectangleLineStyle.width = rectangleLineStyle.height = 200;
Both rectangles have the same width and height. Notice how the one with lineStyle is much smaller?
I’m not sure what the problem is, but there seems to be a fix (kind of).
Through some trial and error I found that if you use CapsStyle.ROUND and JointStyle.MITER like so, the problem disappears:
graphics.lineStyle(3, 0xff0000, 1, false, LineScaleMode.NONE,
CapsStyle.ROUND,
JointStyle.MITER);
However, it’s not perfect. If you have a much smaller rectangle, let’s say you create:
drawRect(0,0,10,10);
Instead of:
drawRect(0,0,50,50);
Then you will still notice a bit of a difference.
If you want to make a rectangle with lineStyle that can be scaled and you want to get rid of this problem completely, an easy fix wold be make the rectangle bigger and scale it down instead of making it smaller and scale it up. In this scenario, the visual rectangle seems to maintain the real width and height values.
Greetings Card Flash Application
I have worked on this application for a few months and now I see it’s finally implemented into greetingsisland.com.
The project was for two Flash applications, Cards and Invitations, both very similar with very few different features.
It lets you make your own greeting card and invitation design. It’s great looking and easy to use, especially for kids. After you’ve made the perfect greeting, you can either print it on your home printer or save it as a PDF file.
The development itself was demanding and very rewarding, as I got to use techniques like singleton pattern, I’ve used the Facebook API to retrieve photos from Facebook albums and I’ve learned some new coding styles from my friend Biro Barna.
Go on, check it out and let me know if you like it
AlivePDF download and save to server
Today I found myself needing to implement AlivePDF into a project that needs to generate a PDF, save it on the server and download it to the user’s computer.
Since I didn’t find any information about how to do this (and I found some other people trying to find out how it’s done) I thought I should give it a try. I posted the final result below if someone else needs to know how to both save the PDF file on the server and download it to the user’s computer.
ActionScript 3 AlivePDF code:
_pdf.save(Method.REMOTE, "save.php", Download.ATTACHMENT, "MyFile.pdf");
PHP code that will save the file on the server (inside a specified folder) and save it to the user’s computer too:
<?php if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){ $pdf = $GLOBALS["HTTP_RAW_POST_DATA"]; $name = $_GET["name"]; $save_to = "pdf/". $name; file_put_contents($save_to, $pdf); // add headers for download dialog-box header('Content-Type: application/pdf'); header('Content-Length: '.strlen($pdf)); header('Content-disposition:'.$method.'; filename="'.$name.'"'); echo $pdf; } else{ echo "Encoded PDF information not received."; } ?>
Convert values within a range to values within another range
Today I’m sharing with you a little utility that I find myself using a lot lately. This utility is a value convertor that you can use in those times when you need to make a volume slider or something similar where you’ll need to change a value and a value range.
package com.vamapaull.utils { public class ValueConvertor { public static function convertRange(originalStart:Number, originalEnd:Number, newStart:Number, newEnd:Number, value:Number):Number { var originalRange:Number = originalEnd - originalStart; var newRange:Number = newEnd - newStart; var ratio:Number = newRange / originalRange; var newValue:Number = value * ratio; var finalValue:Number = newValue + newStart; return finalValue; } } }
Control a Flash Game with your iPhone
Some programmers from Germany developed a great Flash game that uses your iPhone/iPod Touch to control the game actions.
The concept is very interesting and I could see this being applied on lots of old-school arcade games that are ported to Flash.
After learning about WebSockets we were eager to build a website around this technology. As we are a bunch of oldschool nerds it was obvious to transform the iPhone into a gamepad controlling a Flash Website.
Source: WeekendContent.com
Timecode Utility
Today I’m sharing simple utility that I use from time to time when I need to convert time (see what I did there?
)
It’s very useful if you build a FLV player for example, and want to convert the time into minutes:seconds
Example of how to apply it to your project:
import com.vamapaull.utils.TimeUtil; time.text = TimeUtil.getTimecode(timeValue);
Results:

The ActionScript class:
package com.vamapaull.utils { public class TimeUtil { public static function getTimecode(value:Number):String { var t:Number = Math.round(value), min:Number = Math.floor(t/60), sec:Number = t%60, tc:String = ""; if(min < 10) tc += "0"; if(min >= 1) { if (isNaN(min) == true) tc += "0"; else tc += min.toString(); } else tc += "0"; tc += ":"; if(sec < 10) { tc += "0"; if (isNaN(sec) == true) tc += "0"; else tc += sec.toString(); } else { if (isNaN(sec) == true) tc += "0"; else tc += sec.toString(); } return tc; } } }
Device Shake – Accelerometer
Here you have an easy way to detect shakes on mobile devices with equipped accelerometer:
var lastShake:Number = 0; var shakeWait:Number = 600; var acc:Accelerometer = new Accelerometer(); acc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate); function onAccUpdate(e:AccelerometerEvent):void { if(getTimer() - lastShake > shakeWait && (e.accelerationX >= 1.5 || e.accelerationY >= 1.5 || e.accelerationZ >= 1.5)) { shakeIt(); lastShake = getTimer(); } } function shakeIt() { trace("device has been shaked"); }
Enjoy!
First encounter with AIR for Android
Today I made some experiments with AIR for Android. The process was very smooth and I like how simple everything is, in just a few minutes I managed to compile an application and play with it on my Android device. Totally love the way that I can reuse the ActionScript 3 code and make beautiful applications for Android!
Not so many good words about the Android Market. I started an account, then I was asked to pay a fee of $25 and then when my account was created I noticed that I can’t really make paid applications for the Android market since Google Checkout is not available in Romania. How messed up is that? You want people to develop applications for your marketplace, you request a fee and then they have no way to at least get some of that money back. It’s not that I can’t live without 25 bucks, but that really sucks, I feel like I’m giving them money so I can develop for their marketplace and help it grow a little more (so they can earn even more money). I love Flash related technologies and Android, but this doesn’t have any logic.
Anyway, I tried to implement an older youtube player into my AIR application so I can test it out and see how it works. The problem was that when I played a video and hit the hardware back button on my device, the video was still playing because the application minimized instead of closing (as I imagined it would). Then I started to search for a solution, and sure enough, I found it very fast on Tom Krcha’s blog. To close the button when you hit the back button you first need to register a handler:
if(Capabilities.cpuArchitecture=="ARM") { NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys); }
Then you need to make the function for that handler:
function handleKeys(event:KeyboardEvent):void { if(event.keyCode == Keyboard.BACK) NativeApplication.nativeApplication.exit(); }
That’s it. I will continue to work with AIR for Android and hopefully make some cool apps
This is amazing! 3D Flash Game with P2P Multiplayer
I have to say, a Multiplayer 3D Game running in Flash Player is really exciting!
The future of gaming will change from now on. Take a look and tell me what you think
Interesting videos from MAX 2010
I have found some very interesting videos from MAX 2010 and I want to share them with you, I believe you’ll love the new stuff as I do!
Video Tapestries:
Read More
Photo camera wooden knob – made the news
The other day, a photo that I made and published on my flickr profile got picked by gizmodo.com and, consequently, got a lot of attention. It’s a photo of a wooden control knob from my old Fujifilm S5600 FinePix digital photo camera.
I’m really happy with the way the new knob looks and feels.
To all the gizmodo readers I want to say that my friend is a good friend and I appreciate the time end effort he put into this little wooden knob.
Simple AS3 mp3 player
Last night I was browsing around 365psd.com and I found a very interesting design for an mp3 player. Then I thought it would be a good idea to make it functional with Flash and ActionScript 3.0 and then share it for free on my blog
Source files:
mp3_player.zip (1.4 MiB, 2,464 hits)











