jpauclair

*Edit january 2012*

A New faster version is available here: http://www.sociodox.com/base64.html

*End edit*

 

A few weeks ago I started a personal project that needed to send binary data to a text (not binary) receiver. This couldn’t be done without encoding the binary data in a format accepted by the receiver. There is a few well know encoder: Base64, yEnc, etc.
Base64 can have a 30% size overhead (compare to yEnc) but it’s fast and easy to use. I chose Base64.

While searching the net for some Base64 lib in as3, I found the class inside the as3Crypto package, and one from the PHPRPC protocol.

So I started with those lib. DAMN it was slow.

So why after a few years of as3 there is still no optimized library for something that common?

I went through both lib and optimized what I could. The final version is ~700% faster with…

View original post 505 more words

Creating a simple ActionScript 3 class

http://www.adobe.com/devnet/flash/quickstart/creating_class_as3.html

How to use key events in Flash applications for samsung smart TV?

There are two ways that key events can be used:

  1. handling the keys directly in Flash
  2. handling the keys in Javascript and calling Flash functions using the ExternalInterface library

Tips to choose one of this methods:

  • If there are many complicated animations in the app, then using the second method may slow it down, beacuse ExternalInterface takes a lot of memory to process.
  • When using method 1., not all remote keys can be interpreted by the Flash keyhandler. Only the following keys can be handled correctly:
    • navigation keys
    • color keys
    • playback keys
    • numeric keys
    • return and exit keys

    If you need to use other keys, it can be done only through ExternalInterface.

  • The only way to implement volume control in method 1. is unregistering the volume keys in Javascript, so that the native TV handling can be done.
  • When using method 2., the volume control can be implemented within the Flash app, or unregistered as above.

When using method 1, Here are the keycodes for flash keyHandler,

Keys KeyCode
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
0 48
pre-ch
vol-
vol+
info
mute
ch+
ch-
chlist
menu 77
fav.CH
tools 84
return 35
up 38
down 40
right 39
left 37
enter 13
smarthub
exit 36
red 34
green 32
yello 8
blue 33
rewind 67
pause 80
forward 68
rec
play 65
stop 66

 

image smooth in actionscript 3.0

In AS2.0, we had a big issue with the image flickering on dynamic images, In AS 3.0 its easy with the simple codes.

here are the code that you can easily use,

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.display.Bitmap;

var loader:Loader = new Loader()
loader.load(new URLRequest("wiki.jpg"))
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleted)

function loadCompleted(_event:Event):void
{
var bit:Bitmap = loader.content as Bitmap
bit.smoothing = true
loader.scaleX = loader.scaleY = 1.5
}

Image

access stage from class without adding..

Hi,

Here I have given the easiest way to access stage from a class file without using ADDED_TO_STAGE,

We can access the stage by passing a reference of stage in a class file…

Here i have given you a sample code to access….

in AccessStageByReference.as


package{

	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.KeyboardEvent;

	public class AccessStageByReference {
		
		private static var initialized:Boolean = false;		
		
		public function initialize(stage:Stage) {
			if (!initialized) {
				// assign listeners for key presses and deactivation of the player
				stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
				stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
				trace(stage)
				
				initialized = true;
			}
		}
		
		function keyPressed(_event:KeyboardEvent):void{
			trace("KeyPressed")
		}
		
		function keyReleased(_event:KeyboardEvent):void{
			trace("keyReleased")
		}
		
		function clearKeys(_event:KeyboardEvent):void{
			trace("clearKeys")
		}
	
	}
}

you can send a reference for stage into the class by using initialize method..

jujst code like below in the .fla file

var aa:AccessStageByReference = new AccessStageByReference()
aa.initialize(stage)

AS3->openFrameworks at DotBrighton (via James Alliban)

Definitely you need to look at this..

AS3->openFrameworks at DotBrighton It was great to be invited to speak at DotBrighton (formerly FlashBrighton) by Flash maverick Seb Lee-Delisle. I saw this as an excellent opportunity to talk about getting started with openFrameworks from the perspective of an Actionscript developer. The session was pretty tech heavy but it went well with plenty of questions throughout and lots of positive feedback afterward. As promised, the source code is now available here. You can also get th … Read More

via James Alliban

Top five benefits of ActionScript

  1. Achieve greater performanceActionScript 3 was written from the ground up with performance in mind. Depending on the content, you can see a significant increase in performance. This means that your existing content may run smoother, and your new content can do more, while using the same amount of CPU resources.
  2. Leverage new Flash Player APIsAdobe Flash Player 9 and 10 includes a ton of new features which can only be used through ActionScript 3. These include much easier XML APIs via E4X, more advanced display list manipulation, or doing advanced image manipulation with Pixel Bender filters. As a general rule, new ActionScript-based features added in the future will only be available via ActionScript 3.
  3. Leverage community libraries and APIsAlmost all of the major new libraries released by the community are built with ActionScript 3, and include everything from the Papervision3D full 3D engine library to Grant Skinner’s Gtween animation library.
  4. Troubleshoot code more easilyThe ActionScript 3 compiler provides options for much stricter error checking, which means it is more likely you are going to find bugs and errors before you even begin to run your content. When you do find errors, you can take advantage of some of the new and more advanced debugging features to track them down (and of course, you can still use trace()).
  5. Develop content for multiple platformsActionScript 3 is the standard language used across the Adobe Flash Platform. Moving forward, it is the language that Adobe will focus on supporting in existing and new players (like Adobe AIR), servers, and products. Flash Player 10 supports ActionScript 3, and its use is required for developing for Adobe Flex and Adobe AIR content. In addition, Adobe is working on updating its mobile runtimes to ActionScript 3. In the future, you can expect that new Flash Platform products, runtimes, and services from Adobe will use ActionScript 3.

    thanks to adobe…..

get charectors between two charectors in string

String.prototype.between = function(i1, i2)
{
 var iA:String = this.indexOf(i1) + i1.length;
 if (i1 != i2 && this.indexOf(i1, iA) == -1)
 var iB:String = this.indexOf(i2, iA);
 else
 return this.substring(iA).between(i1, i2);
 return this.substring(iA, iB);
};

remove an element from an array Prototype


Array.prototype.remove = function(i) {
 this.splice(i, 1);
};

myArray = new Array("0", "1", "2", "3", "4", "5", "6");

myArray.remove(5, 1);
trace(myArray)

myArray.remove(2, 1);
trace(myArray)

myArray.remove(2, 1);
trace(myArray)
/*
0,1,2,3,4,6
0,1,3,4,6
0,1,4,6
*/

New iPhone Developer Agreement Bans the Use of Adobe’s Flash-to-iPhone Compiler

Prior to today’s release of the iPhone OS 4 SDK, section 3.3.1 of the iPhone Developer Program License Agreement read, in its entirety:

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.

In the new version of the iPhone Developer Program License Agreement released by Apple today (and which developers must agree to before downloading the 4.0 SDK beta), section 3.3.1 now reads:

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).

My reading of this new language is that cross-compilers, such as the Flash-to-iPhone compiler in Adobe’s upcoming Flash Professional CS5 release, are prohibited. This also bans apps compiled using MonoTouch — a tool that compiles C# and .NET apps to the iPhone. It’s unclear what this means for tools like Titanium and PhoneGap, which let developers write JavaScript code that runs in WebKit inside a native iPhone app wrapper. They might be OK. This tweet from the PhoneGap Twitter account suggests they’re not worried. The folks at Appcelerator realize, though, that they might be out of bounds with Titanium. Ansca’s Corona SDK, which lets you write iPhone apps using Lua, strikes me as out of bounds.

I originally thought this would ban games written using Unity3D, but perhaps not — Unity3D produces a complete Xcode project and Objective-C source files, so it’s more like a pre-processor than a cross-compiler. Hard to tell. If you forced me to bet, though, the fact that developers are writing C# code puts Unity3D on the wrong side of this rule.

There was no mention of this change during the announcement event today, but the language in the agreement doesn’t leave much wiggle room for Flash CS5. It could hardly be more clear if they singled out Flash CS5 by name. (Wonder what Adobe does now? CS5 is thisclose to release and the iPhone compiler is the flagship feature in this version of Flash. They’re pretty much royally fucked.)

I’m not sure how exactly Apple intends to enforce this, but my understanding is that iPhone apps produced by Flash CS5 are easily identifiable as such by inspecting the contents of the app bundle. I’m not sure if there are any “intermediary translation or compatibility layers or tools” which produce app bundles that are indistinguishable from app bundles produced by Xcode and the official SDK.

Update: To be clear, I do not think that Apple is singling out Flash CS5. I do think, though, that Flash CS5’s cross-compiler epitomizes the sort of meta-frameworks Apple is not going to allow. Same goes for MonoTouch. What Apple doesn’t want — and as we see now, is not going to allow — is for anyone other than Apple to define the framework for native iPhone apps. What Apple is saying here is, if you’re going to write a native iPhone app, then you need to target our platform; if you want to do something else, then target the iPhone with an optimized web app. I.e., the iPhone OS supports two software platforms: Cocoa Touch and the web. Apple isn’t going to let anyone else build a meta-platform on top of Cocoa Touch. I think this comment at Hacker News from “raganwald” nails Apple’s perspective on this.

Thanks to Daring Fireball…