Archive for the ‘actionscript’ Category

HOWTO Create a Facebook App using FlexBuilder

Jun
24

So for a couple of weeks, I’ve been messing around w/ building a simple app using Facebook. I decided to use the new ActionScript 3 API created by Adobe and Facebook. I wanted to do a little tutorial because some of this information is hard to understand since most of the API has definitions like, ” “.

In this tutorial I will show you how to login to Facebook, retrieve your friends list and populate a TileList with their pictures. Ok, let’s get started.

Read more »

Roman Numeral/Arabic Convertion AIR App – Johnny V Now Available

Dec
25

Merry Christmas, I got you guys present.

I was looking for a need to make an AIR app, though this isn’t the best one, I turned my converter class into one. Introducing Johnny V.

How to convert Roman Numerals and Arabic numbers in ActionScript 3

Dec
17

This past week I worked on a porting exercise. I have always wanted to find out how you convert Roman Numerals to Arabic numerals and vice versa. So I starting searching and found a bunch of bloated code for converting these numbers then I stumbled on this page.

So in a few hours of screwing around w/ the loops (typing this correctly took a bit) I got it ported. Porting is fun cause all you have to do is translate.

Here is the zip flie and Here is the class.

package com.joshspoon.etc.utils
{
	public class NumberUtils
	{
		public function NumberUtils(){}
 
		public static function romanize(num:int):String {
			var numerals:Array = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X",
										"IX", "V", "IV", "I"];
 
			var numbers:Array  = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
 
			var lookup:Object = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1}
 
			var roman:String = "";
 
			var i:int;
 
			  for( i = 0; i < numbers.length; i++)
			  {
				while(num >= numbers[i])
				{
					roman += numerals[i];
					num -= numbers[i];
				}
			  }
			  return roman;
			}
 
		public static function deromanize( roman:String ):int {
 
			var numerals:Array = ["I", "V", "X", "L", "C", "D", "M"];
 
			var numbers:Array  = [1, 5, 10, 50, 100, 500, 1000];
 
			var roman:String = roman.toUpperCase();
 
			var arabic:int = 0;
 
			var i:int = roman.length;
 
		    var compare1:int;
			var compare2:int;
 
			while (i--) {
 
		  	var letter:String;
	  		var listLetter:String;
 
		  	for (var j:int = 0; j < = numerals.length - 1; j++)
		  	{
		  		letter = roman.charAt(i);
		  		listLetter = numerals[j];
		  		if(listLetter == letter)
		  		{
		  			compare1 = numbers[j];
		  		}
		  	}
 
		  	for (j = 0; j <= numerals.length - 1; j++)
		  	{
		  		letter = roman.charAt(i + 1);
		  		listLetter = numerals[j];
		  		if(listLetter == letter)
		  		{
		  			compare2 = numbers[j];
		  		}
		  	}
 
		    if (compare1 < compare2 )
		      arabic -= compare1;
		    else
		      arabic += compare1;
		  }
		  return arabic;
		}
 
	}
}

Using Flash Player 10 to produce Dynamic Musical Notes

May
20

image of swf flash player 10 guitar tunerSo after 13 year of off and on drumming I have learned a thing or two about music. Not much about tuning a guitar. Thanks to a class that I got a D in, Musical Acoustics, I know every note produces a frequency and a wavelength. With that you can now you Flash to produce a frequency and that is what I did, the six notes from left to right are the notes of a regularly tuned guitar.

Since I lost my Musical Acoustics book from UNT I had to look it up to find the Frequency of All Notes

and that pick the ones I wanted starting w/ E4.

So if you don’t have a guitar tuner…here you go.

View Code:

Read more »

Flash Player 10 Dynamic Sound Generation

May
20

I miss writing classes w/ 50 or so lines of code and here is one. This is a take off of Lee Brimelow’s Example of Dynamic Sound Generation. I’m using the BitmapData to create a tone.

[as]

package
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.URLRequest;
import flash.system.Capabilities;
import flash.text.TextField;

public class DynamicSound extends Sprite
{
private var sound:Sound;
private var noise:Number = 0;
private var _loader:Loader;
private var _bm:Bitmap;
private var _verText:TextField;
public function DynamicSound():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
_verText = new TextField();
_verText.text = Capabilities.playerType + ” (” + Capabilities.version + “)”;
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
_loader.load(new URLRequest(“http://www.scarlet.nl/~ivo/photo_ASTRO3.JPEG”));

}

private function onComplete(evt:Event):void
{
_bm = Bitmap(_loader.content);
addChild(_bm);
addChild(_verText);
sound = new Sound();
sound.addEventListener(Event.SAMPLES_CALLBACK, onCallback);
sound.play();
}
private function onCallback(e:SamplesCallbackEvent):void
{
for(var i:uint=0; i<512; i++)
{
noise += _bm.bitmapData.getPixel(mouseX, mouseY)/ 44100;
var sample:Number = noise * Math.PI * 2;
sound.samplesCallbackData.writeFloat(Math.sin(sample));

sound.samplesCallbackData.writeFloat(Math.sin(sample));
}
}
}
}

[/as]

Quick and Dirty!

How to compile and examples for Flash Player 10 or ASTRO BETA

May
16

As many of you know ASTRO is in Public beta.

Download browser plugin

Here are some links on how to compile:

Text instruction – by Mike Chanmbers

Video Instruction – by Lee Brimelow

Flash Magizine Article

A promising sound example:

flash produced sound example – by Keith Peters

Here is my “3D” example, quick and dirty:

[as]

package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Vector3D;
import flash.net.URLRequest;

public class ASTRO extends Sprite
{

private var _loader:Loader;
private var mc:MovieClip;
public function ASTRO()
{

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.EXACT_FIT;
_loader = new Loader()
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete, false, 0, true);
_loader.load(new URLRequest(“record.gif”));

}

private function loadComplete(evt:Event):void
{

mc = new MovieClip();
mc.rotationY = 0;
mc.rotationZ = 0;

stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove, false, 0, true);
mc.opaqueBackground = true;
_loader.x = – (_loader.width * 0.5);
_loader.y = – (_loader.height * 0.5);
mc.addChild(_loader);
mc.x = (_loader.width * 0.5);
mc.y = (_loader.height * 0.5);
addChild(mc);

}

private function onMove(evt:MouseEvent):void
{
mc.rotationZ = stage.mouseY;
mc.rotationX = stage.mouseX

}
}
}
[/as]

Also here are some classes that I saw through code completion. I don’t really know what to do with them yet. Maybe someone else will and will let me know (I have too much work and GTAing to do :) ).

  • flash.text.engine Package (over a dozen classes)
  • __AS3__.vec.Vector (that is wierd)
  • flash.display.GraphicsBitmapFill
  • flash.display.GraphicsPathCommand
  • flash.display.TriangleCulling (that sounds interesting)
  • flash.geom.Vector3D
  • flash.filters.ShaderFilter

Happy Coding!

How to use Bitmap and BitmapData in ActionScript 3 – v2

Apr
23


Alright, in this example, I am cutting each pixel in an image and piecing it back together again. Only this time I animating the pixel to a new location, piecing back the image at 200%. I think this can open a lot doors in what you can do with a bitmap. Read more »

How to use Bitmap and BitmapData in ActionScript 3 – v1

Apr
21

snapshoot of bitmapData  test

So the last couple of weeks I have been jacking around w/ Bitmaps and BitmapData. I’ve always wanted to try it but never had the courage. Now that I have, I wish I’d have done it sooner.

In this first example I’m just copying each pixel throwing it to the wind and using Tweener to animate it to a spot. I don’t think Tweener is the best option course as you can see it runs slow. I’m also using Grant Skinner’s Memory Gauge to illustrate how slow it is. This is just a proof of concept anyway.

Read more »

How to add and remove Mediators in a actionscript-3 puremvc app

Mar
30

So since PureMVC has updated twice and also I never talked about garbage collection of the app, I have refactored PurelyKuler to work with PureMVC 2.3. Thate are quite a few changes, some being:

  1. the framework is being ported to many languages like PHP, Ruby, Python, Coldfusion, C# and many others.
    [as]import org.puremvc.as3.interfaces.IFacade;
    import org.puremvc.as3.patterns.facade.Facade;[/as]
    as oppose to
    [as]import org.puremvc.interfaces.IFacade;
    import org.puremvc.patterns.facade.Facade;[/as]
  2. there is a new way to notify observers:
    [as]facade.sendNotification(PurelyKulerConstants.STARTUP, app);[/as]
    as oppose to
    [as]facade.notifyObserver(new Notification(PurelyKulerConstants.STARTUP, app))[/as]
  3. also the Mediators are can be named from outside the class, so you can have many instances of the class and remove specific instances and not all.public function PurelyKulerMediator(mediatorName:String = null, viewComponent:Object=null){
    _tf = new TextField();

    super(NAME, viewComponent);// the colorContainer
    }
    Those are just a few.

Alright back to PurelyKuler.

Read more »

How to use the FileSystem in AIR to find the users directory folders

Mar
1

I was messing around last night with AIR and I stumbled apon this:

  1. start an AIR app in flash cs3
  2. add a list component
    1. name it dir_list
  3. drop the code below in the actions panel
  4. And Viola!
  5. PS – PC people, I put a test to see if My Documents in in that Directory.

filestream.jpg

[as]

import flash.filesystem.*;

var userDirFiles:Array = File.userDirectory.getDirectoryListing();
for (var i:uint = 0; i < userDirFiles.length; i++) {
if (userDirFiles[i].isDirectory) {
//this.display_txt.text = String(userDirFiles[i].nativePath);
dir_list.addItem({label:userDirFiles[i].nativePath })
var tmpString:String = userDirFiles[i].nativePath;
if(tmpString.search(/My Documents/) != -1)
{

dir_list.addItem({label:”working”});
break;
}
}
} [/as]