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;
		}
	}
}
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 &lt; 10)                  tc += "0";                          if(min &gt;= 1)
            {
                if (isNaN(min) == true) tc += "0";
                else tc += min.toString();
            }
            else 
                tc += "0";
 
            tc += ":";
 
            if(sec &lt; 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!

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, 2,169 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 😀

Source files:

  mp3_player.zip (1.4 MiB, 8,990 hits)