Archive for the 'Actionscript 3' Category

11
May

Adobe Share ActionScript library goes community - Updated! Now with PDF Support!

sharelogolong.jpg

Don’t you just love an exciting headline. If you haven’t heard by now, Share (Document Services API) is an online service provided by Adobe that allows you to share, publish, and organize documents online. Share is already a good service, but it can be an even better service with a little help from all of us. How can we make the service better?

1. Use the service and give feedback on the Share Forum. Whether you’re happy or not they want to hear about it. Have a feature idea, pass it on.
Share Forum
Share API Forum

2. Tell other people about the service. Its 1gb of free space for your documents. Who doesn’t like free.
https://share.acrobat.com

3. Create and share your own projects around the service.

4. Contribute to open source projects that use the Share API.

There are many open source libraries that allow you to easily use the Share Service in your applications (listed at the bottom). One of these libraries is the ActionScript library. Developed internally at Adobe, it has the full original functionality of the service but has fallen behind in the latest revisions of the Share Service. So when speaking to Fang Chang (Adobe Product Manager in charge of the Share APIs) this past week I offered to help bring an updated version of the ActionScript library into the hands of the community. Fang who is a very patient man, (listened to all my feature idea ramblings) felt like it would be a great move. So here we are.

What has been done?

1. The as3 library has been updated to work with the new endpoint and pdf creation support has been added
2. Updated AirShare demo for the release version of AIR.
3. The code has been checked into subversion

4. Documentation has been generated

5. A release has been made that includes the updated source/example.

Example of upload with pdf creation:

import com.adobe.share.api.ShareAPIToken;
import com.adobe.share.api.ShareAPIEvent;
import com.adobe.share.api.ShareAPIUser;
import com.adobe.share.api.ShareAPI;
 
private var _shareAPI:ShareAPI = new ShareAPI("<api key>", "<secret>");
private var _shareAPIUser:ShareAPIUser = new ShareAPIUser("<share user name>", "<share password>");
 
private var _file:File = new File();
 
private function initApp():void{
	var shareAPIToken:ShareAPIToken = _shareAPI.login(_shareAPIUser);
 
	shareAPIToken.addEventListener(ShareAPIEvent.API_AUTHENTICATED, function():void{
		_file.browse();
		_file.addEventListener(Event.SELECT, onFileSelected);
		_file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onFileUploadComplete);				
	});
 
}
private function onFileSelected(event:Event):void{
	_shareAPI.uploadFile(_shareAPIUser, _file, null, _file.name, "", true, true);
}
private function onFileUploadComplete(event:DataEvent):void{
	trace("complete");
}

Want to contribute to the Library?
Please contact me or select join from the project site.

Other Share Libraries:
Java Library
Ruby (Developed by Hideyuki KATO) Ruby
Python (Developed by Vivek Kapoor) Python
Cold Fusion (Developed by Ray Camden) Cold Fusion

09
Mar

My code look pretty one day (or turning your GeSHi install into a service and using it with AS3)

File this one under “when I could have been creating something useful, I created this”

Hmmmm

I’ve been using PrivatePaste.com quite often of late and thought hmm… it would be simple to create a quick as3 library for using the service. Unfortunately PrivatePaste isn’t intended to be used as a web service. This means we can post and get a result, but it will be html. The site also lacks a crossdomain.xml file. While parsing the HTML using a regular expression, it occurred to me that privatepaste just uses GeSHi. A php open source library for syntax highlighting.

Since I already have the GeSHi wordpress plugin setup on this blog, I figured why mess around with parsing an HTML page when I can just make a quick syntax highlighting service myself. All you need to do is add the following file to the directory containing GeSHi. If you’ve installed the wp-syntax plugin (or any highlighting plugin that uses GeSHi) for your wordpress blog then its under /wp-content/plugins.

include('geshi.php');
 
if ( get_magic_quotes_gpc() ) $_POST['source'] = stripslashes($_POST['source']);
 
$source = $_POST['source'];
$language = $_POST['format'];
$path = 'geshi/';
 
$geshi = new GeSHi($source, $language, $path);
 
if($_POST['linenumbers'] == "true")
	$lineoption = GESHI_NORMAL_LINE_NUMBERS;
else
	$lineoption = GESHI_NO_LINE_NUMBERS;
 
 
$geshi->enable_line_numbers($lineoption);

echo $geshi->parse_code();

Thats it, you now have a GeSHi service. To use your service in ActionScript 3 you can use as3geshilib that I’ve included in the download:
GeSHi AIR

private function parseCode():void{
	var geshiService:GeshiService = new GeshiService();
 
	geshiService.addEventListener(GeshiResultEvent.ON_GET_PARSE_CODE, function(event:GeshiResultEvent):void{
			trace(event);
			htmlDisplay.htmlText = event.data as String;
		});
 
	geshiService.parseCode("SELECT * FROM user_table", GeshiFormatType.SQL, true);
}
geshiservice.zip Includes geshiservice.php, as3geshilib - source included

In the end, what we really have here is an example of how to make a quick php service and use it in ActionScript. Which I guess is not a complete waste of time…

If you just need syntax highlighting in your AS3 project then I would recommend checking out this AS3 code highlighting library http://labs.searchcoders.com/text/. I haven’t checked it out yet, but plan to the next time my code runs off on a tangent.

03
Mar

Pownce Actionscript 3 Library Released - Full API V2.0 Implementation (Upload files and everything)

Now that Pownce has released an official API covering features such as posting files, I decided to go ahead and make an AS3 library for it. I just posted it to googlecode and have only done minimal testing on it. I would appreciate any feedback.

The Pownce team did a terrific job with the API. Easy to use and consistent. I had minimal issues while creating the as3 library.

In my opinion (yeah you can skip this) Pownce is a far better user experience than Twitter. Its like a gobot and a transformer or a dell laptop and a macbook or chocolate torte and hohos. That is the best I an come up with that the moment, yes.

torteHoHos

I could be missing something here… but this API in my mind is a leap forward in the race with twitter.

// Imports omitted for brevity
private const APP_KEY:String = "<your app key>";
 
private var _pownceService:PownceService;
private var _testUsername:String = "<Pownce username>";
private var _testPassword:String = "<Pownce password>";
 
private function initApp():void{
	_pownceService = new PownceService(APP_KEY);
	_pownceService.setAuth(_testUsername, _testPassword);				
}
 
// Example of posting a file
public function testPostAFile():void{
	var file:FileReference = new FileReference();
 
	_pownceService.addEventListener(PownceResultEvent.ON_POST_A_FILE, function(event:PownceResultEvent):void{
			var pownceResult:PownceNotesResult = event.data as PownceNotesResult;
 
			if(pownceResult.success){
				trace((pownceResult.notes[0] as PownceNote).body);
			}else{
				trace(pownceResult.statusCode);
				trace(pownceResult.message);
				trace(pownceResult.request);
			}
		});
 
	file.addEventListener(Event.SELECT, function(event:Event):void{
			_pownceService.postAFile("all", event.currentTarget as FileReference, "File upload test");
		});
	file.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void{
			trace(event.bytesLoaded + "/" + event.bytesTotal);
		});
 
	file.browse();
}
private function testGetNoteList():void{
 
	_pownceService.addEventListener(PownceResultEvent.ON_GET_NOTE_LIST, function(event:PownceResultEvent):void{
			var pownceNoteResult:PownceNotesResult = event.data as PownceNotesResult;
 
			if(pownceNoteResult.success){
				trace(pownceNoteResult.notes.length);
			}else{
				trace(pownceNoteResult.statusCode);
				trace(pownceNoteResult.message);
				trace(pownceNoteResult.request);
			}
		});
 
	_pownceService.getNoteList(_testUsername,null, 100, -1, -1);
}

I’m going to continue to test the library and improve the documentation. Let me know if I missed anything (outside of OAUTH).

Add me to your Pownce http://pownce.com/InitApp/

Existing issue:
One method is not currently working. It is the retrieval of the send to list. I’ve posted information about the issue to the google pownce group and hopefully it will be resolved soon.

29
Feb

Posting a Note/Link to Pownce with ActionScript and the New Pownce v2.0 API

So this morning Pownce finally released a true API that allows us to use the full functionality of Pownce. A while back I posted information on how to do this in a reverse engineered method, but now we can do it without the feeling that we might be doing something bad (although that can be fun sometimes to can’t it).

The code sample below shows how to Authenticate to the service using HTTP Basic Authentication and posts a note/link.

Steps to take
1. Get a pownce account if you don’t have one.
2. Register to get an application key.
3. Use the following code. Change “app_key” to your application key. Change “login” and “password” to user you want to post with.


Private Paste Link to Code

import mx.utils.Base64Encoder;
 
private const APP_KEY:String = "<app_key>";
 
public function initApp():void{
	sendNote(
		"Example of note in the new API.",
		"http://pownce.com/initapp",
		"<login>",
		"<password>"
		);
}
public function sendNote(note:String, link:String, login:String, password:String):void{
	var urlLoader:URLLoader = new URLLoader();
	var urlRequest:URLRequest = new URLRequest();
	var urlVariables:URLVariables = new URLVariables();
 
	var authHeader:URLRequestHeader = new URLRequestHeader("Authorization", "Basic " + base64Encode(login + ":" + password));
 
	urlVariables.note_to = "public";
	urlVariables.url = link;
	urlVariables.note_body = note;
 
	urlRequest.requestHeaders.push(authHeader);
	urlRequest.url = "http://api.pownce.com/2.0/send/link.xml?&app_key=" + APP_KEY;
	urlRequest.data = urlVariables;
	urlRequest.method = URLRequestMethod.POST;
 
	urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);
	urlLoader.addEventListener(Event.COMPLETE, onComplete);
 
	urlLoader.load(urlRequest);
}
private function onHTTPStatus(event:HTTPStatusEvent):void{
	trace(event);
}
private function onComplete(event:Event):void{
	trace(event);
}
private static function base64Encode(data:String) : String
{
    var encoder:Base64Encoder = new Base64Encoder();
	var bytes:ByteArray = new ByteArray();
	bytes.writeUTFBytes(data);
 
    encoder.encodeBytes(bytes);
    return encoder.flush();
}

If you want to hear more of my occasionally relevant information then add me to your friends in pownce: http://pownce.com/InitApp/


Note: I did this example using Flex and used mx.utils.Base64Encoder. If you’re not using Flex you’ll need to use an alternate package for your Base64 encoding.

12
May

Quicktip: Flex Form Validation - Sometimes tapping the user on the shoulder just isn’t enough

Since Flex 360 I’ve been completely engulfed in a large project in which a large portion of it is in yes, Flex. Flex and I have been getting along pretty well but from time to time we rumble a bit. In the case of form validation flex seems to be perfect in almost every way… except that after the validation happens the only signal to the user that something needs to be done is the hightlight around the control. This is the validation equivalent of a tap on the shoulder to the user.

What i wanted was to show was the rollover popup for the first form element the user had to alter in order to have a valid form immediately upon hitting submit. Unfortunately I couldn’t find any method to raise the popup so I wrote a quick little hack that does the job. Its not perfect, but one of the best things I learned from the flex 360 conference was when Jessie Warden said “sometimes you just throw stuff out there and its hot!”. Essentially, what I think he meant was what you do may not always be the best way, but if it does the trick… go with it.

private function setValidationFocus(formObject:Object):void{
formObject.setFocus();
formObject.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
}

valpop.jpg
If anyone knows of a better way to accomplish this task, please send it my way.

thanks -s

18
Jan

ActionScript Example: Creating a Static Function

So a developer I work with was going to use an include file and a prototype for a string altering method he wanted to use throughout his application. The only thing that came to mind was the Mr. Horses catch phrase from Ren & Stimpy.

“No sir I don’t like it”.

I offered the possibility that he might create a utilites class in our namespace with a static function to accomplish his goal. To that he asked “Can you give me an example of how to make a static function”. Well here it is:

First we have our class:

class com.imart.utilities.StringHelper{

function StringHelper(){

}
public static function returnString(passValue:String):String{
return “Here you go:” + passValue;
}
}

Then we can call the method:

import com.imart.utilities.*

example_txt.text = StringHelper.returnString(”Steve”);

Download the example project

10
Nov

VitalStream + ActionScript3 = NetScream Object

As I’m getting into flex2 more I decided to upgrade my multimedia classes to ActionScript3. I use VitalStream for streaming media Not far into it I received the following error:

Error #2126: NetConnection object must be connected.

This would happen whenever I tried to connect to the VitalStream Server.

After digging a little I saw that it was an object encoding error.
After pulling out some hair I started looking around on LiveDocs I found the following:

Connecting exclusively to a server that was released prior to Flash Player 9, such as Flex 1.5 and FlashMedia Server 2. In this scenario, set the static defaultObjectEncoding property to ObjectEncoding.AMF0.

var netConnect:NetConnection;
netConnect = new NetConnection();

netConnect.objectEncoding = flash.net.ObjectEncoding.AMF0;
Setting the encoding correctly upfront will fix your problems and save you some hair.

Thats it for now.

-s




flickr