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.

Using ExternalInterface and JS to make an Expandable Flash Banner

Expandable Banner – How to make it and embed it into your HTML page without affecting the rest of the page.

Today I helped a friend who needed an expandable banner embedded into a news website. At first, I had the instinct to searching on Google and giving him an URL or something where he can read more about this. To my surprise, none of the info I got through search engines was relevant or complete for this specific subject.

This led me to create an example and now I want to share that example with those searching for how to make an expandable Flash banner.

Read More

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? :D )
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;
        }
    }
}

Image and Video Slideshow

Just uploaded a new project to ActiveDen. This is a slideshow that will let you display images and play videos.

You can play video from YouTube, Vimeo or your FLV, F4V, MP4 files.
It can load JPG, SWF and PNG files.

If you want to buy it, please check the image below ;)

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!

For those who say Flash is dying

I started with Flash 5 and many people said Flash will never be good enough and after that I’ve heard many people saying Flash is dying.

A very small part of the dying statement is true.
I believe the market is saturated with Flash portfolios / photo galleries / video players, but Flash is not only that.

I hear many developers who are doing just that and who are complaining about it.

My response is: Try something new! Stop doing the same video/photo galleries every single time and start experiment with different things. The Flash environment has a lot to offer, you don’t need to limit yourself only to galleries and video players.

A lot of those who complain are the stock Flash developers (the ones who sell stuff on ActiveDen and similar marketplaces).
Those people need to understand that any market gets saturated and not all the Flash developers are selling stock files and have a living doing so.

Flash may not be the perfect environment and AcionScript may not be the perfect programming language but I believe a lot of good things can come from Flash if you know how to take advantage of it.

And no, the iPad dose not bring the death of Flash. Not everyone sits on the can to surf the web. And Flash is not limited only to the web.

Paul Calver’s portfolio website

A few weeks ago I started working on some updates for a photography website. The project started a bit slow, but after I managed to get every information from the client I managed to understand what’s needed to be done in order to complete it. This project uses SlideShow PRO (at the request of my client) and SlideShow PRO Director for CMS. I like the final result and that’s why I wrote about this website. Enjoy ;)

What I’ve been up to lately

Lately I’ve been working on a lot of projects, one of them being this audio tool. This is my first Flex (aka. Flash Builder) project and it was delivered with big help from my partner Biro Barna.

The tool is made to let people create their own ringtones. You can simply upload any MP3 file and cut it up to 30 seconds, add fade in / fade out if you want and then give it a name and save it. Then a new page will let you download the ringtone in iPhone format or MP3 format.

I’m in the process of remaking my portfolio site. When it’s done I will post more of my projects.

Darth Vader “no” button


Last night I published my first application on the Android market. It’s just a cool button that plays the famous “noooo” scream made by Darth Vader in Star Wars: Episode III – Revenge of the Sith.

Enjoy! :D

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! :D

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.

Read More

Now you know what I did last summer. Bonus: what I’m working on

It’s been a long time since my last blog post. In the past few months, had time for a little vacation (I went to Anonimul Film Festival) and I worked on some very interesting projects.

Lately, I’ve started working on some projects with Biro Barna (a friend of mine and a highly trained ActionScript developer).

Moreover, I’ve started working with Flash Builder where I code my projects and Flash IDE to compile them. I’m starting to like this work flow, it’s more organized and I feel like I can code faster this way :D

In addition to all this, I’m working on a custom DailyMotion player and I’m using the official API.

The problem right now is that I can’t get the chromeless player to work, I believe it’s a problem with this API or something, I will be doing some more research and see what can be done to fix this problem.

I’ll let you know when or if this project will be done.

Shuffle text menu

This is text shuffle class that will help you make a nice flash menu for your site or your applications. I got inspired from a similar class made by Lee Brimelow. You can use it for open source or commercial projects (do anything you want).

Get Adobe Flash player

  Shuffle Text (20.8 KiB, 1,023 hits)

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 :D

Source files:

  mp3_player.zip (1.4 MiB, 2,464 hits)