Archive

Archive for the ‘Flash’ Category

Screendump my Stage

November 18th, 2009

Often in bug testing phase or just to show something it’s a tideus work to screendump your screen and it get as well a problem if you are dependent by the transparency.

Wrote a small debug class that takes a screen dump of the stage and puts the file on a server (PHP).

So put this PHP on a server somewhere.

<?php
$png = $GLOBALS["HTTP_RAW_POST_DATA"];
$name = date('Y-m-d H.i.s');
$filename = $name.'.png';
file_put_contents($filename, $png);
?>

<?php
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
$name = date(‘Y-m-d H.i.s’);
$filename = $name.’.png’;
file_put_contents($filename, $jpg);
?>

<?php
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];
$name = date(‘Y-m-d H.i.s’);
$filename = $name.’.png’;
file_put_contents($filename, $jpg);
?>

Then you can add this class to you project, required is the adobe core package (http://code.google.com/p/as3corelib/).
Download Screendump.as

To use it first set the URI and stage
Screendump.stage = this.stage;
Screendump.URI = “http://localhost:8888/screendump/dump.php”;

After that whenever you need to take a dump, run
Screendump.takeDump();

Flash , ,

Runtime Fonts with Unicode Range

October 29th, 2009

For a couple of months ago I publish a post about fonts embed with unicode range. There are ways on how to extract the fonts from Flash files with some de-compiling but for those who found the article interesting but never figured out the unicodeRange bit, well there is a solution.

1.) First look on how to setup and use the FontManager
2.) Download UnicodeHexCreator I created to create the unicodeRange.

The AIR Unicode app is used to create the correct unicode range to optimize the amount of bytes that is needed to be loaded. To get the range it’s really simple.

1.) Copy/Paste your entire XML file to the input field (top field)
2.) Select font to use and set class name.
3.) Press convert
4.) Copy/Paste the unicodeRange to the Flex Project that creates the font file.

Download UnicodeHexCreator.

Flash, Flex , , , ,

AMFPHP Failed Responses from Desktop Applications

October 14th, 2009

When sending data between Flash to Server I often use the AMFPHP service. It’s a easy to install and rapid way to send data back and forth. A problem I noticed when running a desktop application on PC was that it kept returning errors but from a MAC it worked just fine. The simple solution is to set the gateway to work as a test server, else the service blocks desktop calls.

Problem: Desktop application from PC getting errors in responses when MAC works fine.
Solution: Open gateway.php line: 106 and change PRODUCTION_SERVER to false.

Flash , ,

Papervision 3D and Maya Camera

September 30th, 2009

Worked with Papervision 3D in a couple of project and trying to simulate the Maya 3D world to Papervision 3D as much as possible to make it easier for the art directors. A big problem has been with the Maya Camera and units. What we did is that the 3d modeler setups a camera in Maya and we are converting the values to the camera in actionscript to fit Papervision 3D.

What we are looking at is the FOV (focal length), the flash convert value is (xv / (2 * Math.tan(Math.PI * fov / 360))) /1.5;

Bojidar Dimitrov has an 1.5 lens converter that works excellent:
http://www.bdimitrov.de/kmp/technology/fov.html

By using the Maya Focal Length thru the converter and adding that to this formulas variable xv, you will get a Papervision 3D camera that is the same.

1
2
3
4
5
6
// FOV from Maya
var fov:Number = 35;
// FOV to F from http://www.bdimitrov.de/kmp/technology/fov.html
var xv:Number = 45.741390734365076;
var focus:Number = (xv / (2 * Math.tan(Math.PI * fov / 360))) /1.5;
camera.focus = focus;

Please visit Papervision 3D blog for great info.

Flash, Flex , , ,

Flash Library Sounds “break”

July 6th, 2009

Working in a sound/voice heavy project right now, we keep updating the sound files in the FLA files all the time and they just keep crashing. When playing the sounds in Flash it gets a high pitch noise and is all scramble.

Solution:
Select the files in library and choose UPDATE, then Clear ASO Cache and export the file. Irritating bug I know but this seems to get my files to play correctly.
PS: Adobe Flash CS4 with WAV sounds.

Flash , , , , ,

Webcam Privacy DENY

June 8th, 2009

Working with a online webcam application and when trying my user-cases I noticed an irritating problem.

When connecting a webcam class to a Video the Privacy settings automaticly appear.
video.attachCamera( camera ); 

But if the user clicks DENY instead of ALLOW you can get into a little problem. My application needs a webcam so what I do is to show the user some copy and telling them to ALLOW the webcam or go somewhere else to play.

To check if the first time was allowed or not is easy with 
camera.addEventListener(StatusEvent.STATUS, onCameraStatus);
but this is only triggered first time, event if I create a new Camera and Video class. 

Solution
After the first event I set a variable that the user has already got the Privacy window. IF the user selects DENY and I want to give them another change (after my nice warning window) I do everything EXACTLY the same way, JUST ADD
Security.showSettings(SecurityPanel.PRIVACY);
If it’s the next try.

Flash , , , , ,

Social Network Links

April 11th, 2009

Wanted to post some Social media links on a site that I’m building but couldn’t find any good summary information, well, so here we go.

share_facebook

 

 
Facebook

http://www.facebook.com/sharer.php?u=’+encodeURIComponent(u)+’&t=’+encodeURIComponent(t) 

u = url to site
t = title of link

share_delicious

 

Delicious
“http://delicious.com/save?url=”+u+”&title=”+t;
u = url to site
t = title of link
m = metadata for link

share_myspace

 

MySpace
“http://www.myspace.com/Modules/PostTo/Pages/?u=”+u+”&sa=2&t=”+t+”&c=” 
u = url to site
t = title of link

share_digg

 

Digg
“http://digg.com/submit?url=”+u+”&title=”+t+”&bodytext=”; 
u = url to site
t = title of link

share_twitter

 

Twitter
“http://twitter.com/home/?status=”+t+” “+u
u = url to site
t = title of link

share_stumble

 

 
Stumbleupon

“http://stumbleupon.com/submit?url=”+u+”&title=”+t 
u = url to site
t = title of link

Createad a simple js file to use for html pages or why not Flash applications. Send the types; facebook,delicious,myspace,digg,twitter or stumbleupon. 
socialShare(type, link, title);

function socialShare(type,link,title,meta)
{
	var shareURL;
	var u = encodeURIComponent(link);
	var t = encodeURIComponent(title);
	var m = encodeURIComponent(meta);
	if(!m) m = t;
	var w = 626;
	var h = 436;
	switch(type)
	{
		case "facebook" :
			shareURL = "http://www.facebook.com/sharer.php?u="+u+"&amp;t="+t;
			break;
		case "delicious" :
			shareURL = "http://delicious.com/save?url="+link+"&amp;title="+title+"&amp;q="+title+"&amp;meta="+encodeURIComponent(m);
			break;
		case "myspace" :
			shareURL = "http://www.myspace.com/Modules/PostTo/Pages/?u="+link+"&amp;sa=2&amp;t="+title+"&amp;c=";
			break;
		case "digg" :
			shareURL = "http://digg.com/submit?url="+link+"&amp;title="+title+"&amp;bodytext=";
			w = 730;
			h = 550;
			break;
		case "twitter" :
			w = 760;
			shareURL = "http://twitter.com/home/?status="+title+" "+link
			break;
		case "stumbleupon" :
			shareURL = "http://stumbleupon.com/submit?url="+link+"&amp;title="+title
			break;
	}
	window.open(shareURL,"sharer","toolbar=0,status=0,scrollbars=yes,resizable=yes,width="+w+",height="+h);return false;
}

Download Social Share javascript.

Flash, Life , , ,

Tip of the day: Publish Time & Memory Increase

April 1st, 2009

At my company “Hello There” we are currently developing a really cool game that is built on the base of Papervision 3D 2.0 (Great White). We suddenly run into a really really annoying problem.

I could publish the Flash files without any complication but the other two team members couldn’t, and we have the same set of workstations. After a lot of searching it seems somehow that it’s a memory problem and some suggestions points to changing JAVA memory, well, we didn’t get that to work either so we took another solution.

By making the Papervision package to a SWC file it’s already compiled and takes less memory for Flash. If you have a bigger framework you should as well take your time to create a SWC package for it. The publish time will decrease and your will be working happily ever after =)

TIP: Use more SWC, will speed up your work & use less memory.

If you have Flex, here is an easy tutorial on how to create your SWC package.
1.) Create a “Flex Library Project”.
2.) Add your code that you want to compile.
3.) Right click on the project, Properties->Flex Builder Path
4.) Mark all the packages that you want to compile
5.) Finish, just refresh the project to make sure everything is compiled when you change anything. The SWC file is placed in the /bin folder. Ready to use for Flex & Flash.

Did a really short video;
preview image.

Flash, Flex , , ,

XML in Production (lazy)

March 30th, 2009

I’m working a lot with international sites and there can often be times where the deadlines are short, customers aren’t so fast as I wish they where with feedback e.g.

This often messes up translations with XML files. They needs to be resend for changes and as the sites takes interaction you can find that things are missing.

Here is a small tip if you are running out of time, make sure your XML structure is simple, as well make sure that you are using unique id attributes. Then you can just combine the XML files and you don’t really need to go thru hours of copy/paste work.

A small example.
XML 1
<xml>
<gui>
<item id=”replay”>REPLAY</item>
<item id=”start”>START THE GAME</item>
</gui>
</xml>

XML 2
<xml>
<gui>
<item id=”volumeOff”>TURN ON VOLUME</item>
<item id=”volumeOn”>TURN OFF VOLUME</item>
</gui>
</xml>

So what I do is just to add on and on and combine the XML;s.

var copy:XML = levelLoader.getXML("data/en.xml");
var copy1:XML = levelLoader.getXML("data/en01.xml");
var copy2:XML = levelLoader.getXML("data/en02.xml");
copy = copy.appendChild(copy1.*);
copy = copy.appendChild(copy2.*);
 
var volumeOff : String = copy.gui.(@id=="volumeOff");

Flash , , , ,

Runtime Dynamic Fonts for CS4 (fp9), next-gen

February 13th, 2009

Runtime Fonts for Flash is a wonderful way when building apps, even better if you are as me and creating international apps for a lot of countries, you have the language supports and the problem with characters in fonts when staring to look at Greek, Japanese, Korea, Chinese and so on. I have a old Runtime font for CS3 that works pretty well. But when starting to use CS4 I wanted to improve the loading and sharing.

So the idea was to use Flex to compile Font SWF files, a big problem when I use Flash CS4 (fp9) and Flex 3. Flex will not recognize my font SWF file, it will also not recognize my local fonts to embed bold/italic font sets. Using an exported CS3 (fp9) file it works just fine.
Note; fp9 = Flash Player 9.

So lets look of how to do this.
First we need to create our font file.
1.) Create an Flex ActionScript project (I use framework 3.2)
2.) The Class name will be something that we will get later so I renamed my as file to FontHolder.as
3.) Remove the constructor and add the embed tags, example below. Note the unicodeRange tag, these are used to select characters to be embedded, remove to embed the entire font.

package {
	import flash.display.Sprite;
 
	public class FontHolder extends Sprite
	{
		[Embed(systemFont='Verdana', fontFamily='Verdana', mimeType='application/x-font', unicodeRange='U+0061-U+0074')]
		public static const verdana_regular:Class;
 
		[Embed(systemFont='Verdana', fontFamily='Verdana', mimeType='application/x-font', fontWeight='bold', unicodeRange='U+0061-U+0074')]
		public static const verdana_bold:Class;
	}
}

4.) Now you have your font SWF file to use for the project.

So with your font file it’s time to use it in the project. In this example I use my Flex 3 as CS3 development tool., this is because I create Flash Player 9 project. You can of course use only Flash IDE or any other kind of code editor.
1.) Create a new ActionScript project, change the SDK to CS3.
2.) Click next, “Main source folder”, type “src”, this is just to put the files more pretty =), Click Finish.
3.) Create a CSS file that will control the fonts. “default.css”. Just add two classes that we can work with.

h1{
	font-family: Verdana;
	font-size: 24px;
	font-weight: bold;
}
body{
	font-family: Verdana;
	font-size: 12px;
}

5.) Download the FontManager.swc file and add it to your project.

Add SWC HowTo for Flex
6.1.) Create a folder called swc in project folder.
6.2.) Place the FontManager.swc file into the created folder.
6.3.) Right-Click on project folder and select properties
6.4.) In menu choose “ActionScript Build Path”, Choose the tab “Library path”
6.5.) Click on “Add SWC Folder”,  Select the created swc folder and close the windows, all done.

Add SWC HowTo for Flash
7.1.) Create a folder called swc in project folder.
7.2.) Place the FontManager.swc file into the created folder.
7.3.) Open Flash and Publish Settings.
7.4.) Choose the Flash tab and click on Settings next to the script combobox.
7.5.) Choose the “Library Path” tab and add the swc file to the list, all done. 

So, everything is there. How am I using it? Well, this is a dump on the project playground.
dynamic_files1

 

 

 

 

 

 

 

 

To be able to use the fonts they are needed first to be loaded. By default this is the structure for font swf and css file named default. They can be changed by FontManager.name = ‘default’ (the name) and the path with FontManager.path = ‘fonts/’.

The easiest way is to just get the singleton and load it.

var manager:FontManager=FontManager.instance();
manager.addEventListener(Event.COMPLETE, onManagerComplete);
manager.loadStandalone();

When it’s loading just send the textfield, style and text to the FontManager, you can add only textfield and text if you want to add e.g. multiple styles to one textfield.
Here’s some examples.

private function onManagerComplete(event:Event):void
{
	var tf:TextField = new TextField();
	tf.autoSize = TextFieldAutoSize.LEFT;
	tf.border = true;
	tf.rotation = 6;
	FontManager.instance().register(tf, "h1", "abc");
	this.addChild(tf);
 
	var tf1:TextField = new TextField();
	tf1.autoSize = TextFieldAutoSize.LEFT;
	tf1.x = 150;
	tf1.border = true;
	tf1.rotation = 6;
	FontManager.instance().register(tf1, "body", "abc");
	this.addChild(tf1);
 
	var tf2:TextField = new TextField();
	tf2.autoSize = TextFieldAutoSize.LEFT;
	tf2.x = 300;
	tf2.border = true;
	tf2.rotation = 6;
	FontManager.instance().text(tf2, "<h1>abc</h1>\nabc");
	this.addChild(tf2);
}

Flash, Flex , , , , , ,