Category Archives: Actionscript 3

Develop Flash Player 11 and Air 3 Applications (Desktop and Android)

If you haven’t heard already, Flash Player 11 and Air 3 were announced and released at Adobe Max earlier this week. Since it’s out to download, why not take advantage of staying updated and start making cool applications with these new API’s.

Download these files
- You need the AIR SDK

http://blogs.adobe.com/flashruntimereleases/2011/10/04/flash-player-11-and-air-3-now-available/

- You need the PlayerGlobal (.swc)

http://www.adobe.com/support/flashplayer/downloads.html#fp11


Comparing String in Flash AS3

I’m making my first iOS and Android game. While coding this game, I wanted to compare two strings. I thought I could just use someString == stringXYZ. After some tests, I figured out my if statements where not being read. After some searching, I found out to test a string you need to use the Collator class. Once I coded the if statement using the Collator class, my if statement finally worked. Below is some notes on how to use the Collator class.

I want to give credit to the Adobe Flash platform documentation. This is where I found out about comparing strings.

http://help.adobe.com/en_US/as3/dev/WS9b644acd4ebe59998b99a90125fc4fecfb-7ff8.html


var myMatcher:Collator = new Collator("fr-FR", CollatorMode.MATCHING);
if (matcher.equals(string1, string2))
{
trace("we have a match!");
}


Update Facebook Status from Android Air Applications with Extended Permissions

Before I go into details about this exciting experiment with AS3 Facebook API and Android Air, I want to give credit to a few websites.

(The code that I used was from the first source, but used second source as a reference)

http://blog.flash-core.com/?p=233

http://blog.yoz.sk/2010/10/authorizing-facebook-applications-in-android/#more-2481

One of the coolest things about making games, is being able to post to social networks on how well you did. I’m in the middle of developing a Android Air/iOS application and since I’ve developed most of the functionality for the game, I wanted to implement this feature. After numerous hours of searching online and trying different workarounds, I finally made it work! For the purposes of testing, I used the Flash Web Application that I made for this experiment. One of the coolest things about making it work on the Android, you don’t need to change anything or create a new application in Facebook.

Below is snippets of the code that makes this feature work.

_view = new StageWebView();
_view.addEventListener(LocationChangeEvent.LOCATION_CHANGING, viewChangingHandler);
_view.addEventListener(LocationChangeEvent.LOCATION_CHANGE, viewChange);
_view.stage = stage;

_view.viewPort = _space;

var _sAppId:String = "";

var _sRedirectUri:String = "https://graph.facebook.com/oauth/authorize?client_id=_sAppId";

var _sScope:String = "publish_stream, create_event, rsvp_event, sms, offline_access, manage_pages, email, read_insights, read_stream, read_mailbox, ads_management, xmpp_login, user_about_me, user_activities, user_birthday, user_education_history, user_events, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_relationships, user_religion_politics, user_status, user_videos, user_website, user_work_history, email,publish_stream,offline_access,read_stream";

_view.loadURL("https://graph.facebook.com/oauth/authorize?client_id=_sAppId&scope=publish_stream, create_event, rsvp_event, sms, offline_access, manage_pages, email, read_insights, read_stream, read_mailbox, ads_management, xmpp_login, user_about_me, user_activities, user_birthday, user_education_history, user_events, user_groups, user_hometown, user_interests, user_likes, user_location, user_notes, user_online_presence, user_photo_video_tags, user_photos, user_relationships, user_religion_politics, user_status, user_videos, user_website, user_work_history, email,publish_stream,offline_access,read_stream&redirect_uri=http://www.griffinsdesigns.com/Facebook");

private function viewChangingHandler(event:LocationChangeEvent):void{
event.preventDefault();
_view.loadURL(event.location);

}

private function viewChange(event:LocationChangeEvent):void{
var _sRedirectUri:String = "https://graph.facebook.com/oauth/authorize?client_id=_sAppId";

var _sAccessToken:String;
if (_view.location.indexOf(_sRedirectUri) == 0 && _view.location.indexOf("access_token")!=-1){
_sAccessToken = "?"+_view.location.substring(_view.location.indexOf("access_token"), _view.location.indexOf("&expires_in"));
_view.stage = null;
}

}

Make sure you use loadURL, otherwise it will give you an error. The sources listed above, post, “load(new URLRequest( “. That does not work with the newest Air. If you look at my previous article about posting to Facebook, I mention a long URl that you want to redirect to, you want to use that URL as your URL that you will load.

What does this code do?

This code makes a web frame inside your Android Application and will show the Facebook Applicaton. If a new user goes to your application, the frame would show a login screen, like if they want to Facebook from a browser. After the user logs in, they would be sent to a page that lists the extended permissions (assuming you set the application to have extended permissons). Once the user clicks the allow button, they would be sent to the application.

I haven’t tested this on a Android Device. I only tested it by publishing it in Flash. The next thing I need to test is seeing if it would work when publishing it to a iOS application and test it on my iPad 2.

Facebook login screen inside Android Air Appliation

ExtendedPermissions in Android Air


Testing Flash Player 11 (Incubator) with Molehill and Away3D

If you don’t know what Molehill is, your missing out. At Adobe Max, Adobe showed Molehill, which is a 3D API for Flash. A team of developers made a cool car came using Molehill and Flash Player 11, which is called Incubator. You can see a video of the game on youtube. Molehill came out at the end of February.

Before I go any further, I want to give credit to these sources:

http://johnlindquist.com/2011/02/28/quickstart-for-molehill-and-away3d/

http://proxxit.appspot.com/theflashblog.com

http://labs.adobe.com/wiki/index.php/Flash_Player_Incubator#Authoring_for_Flash_Player_11.2C0.2C0.2C58_Incubator

http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=5&subindex=1&aid=263

This example was what I came up with after using all the code that was in the video of source 1, that I mentioned above. The video shows you how to get your first object in the scene and rotating it. I used source 2 as a reference mostly.

After watching the video and coding the example used in the video, I spent a few hours messing around with the Molehill API and Away3D. Away3D is not required, but it speeds up the process in getting the scene setup.

For those of you who don’t know what Away3D is, Away3D is a 3rd party library of code that allows Flash Developers to make 3D in Flash.

The reason for this example was to try Molehill for myself and getting familiar with the API and seeing how fast Flash Player 11 is. I thought it would be cool to see how fast and I can make the models move without having Flash Player quit.

You need Flash Player 11 installed to view this content. You can download Flash Player 11 here:

http://labs.adobe.com/technologies/flashplatformruntimes/incubator/

Molehill & Away3D Example with Flash Player 11

This is how fast I’m making these models rotate at frame rate of 60:

private function continuous(event:Event):void{
_mySquare.rotationX += 8000;
_mySquare2.yaw(8000);
_myView.render();
}

I built the example using Flash Builder “Burrito.” It was interesting to develop Flash in Flash Builder instead of Flash. I mostly code in Flash. One of things I want to improve on is using Flash Builder, which is the reason why I wanted to code in Flash Builder, instead of Flash.

Instructions:

http://labs.adobe.com/wiki/index.php/Flash_Player_Incubator#Authoring_for_Flash_Player_11.2C0.2C0.2C58_Incubator


Other Resources and Examples

http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=5&subindex=1&aid=263

http://www.disturbmedia.com/wiki/index.php/How_to_get_started_with_the_Molehill_API_and_Away3D_40.html#Radiolarian

http://proxxit.appspot.com/theflashblog.com

http://johnlindquist.com/2011/02/28/quickstart-for-molehill-and-away3d/


Using Accelerometer for Flash Mobile Applications

This is tutorial on using the accelerometer for your Flash Mobile applications. This code was modified from an example that I came across from Adobe.

import flash.sensors.Accelerometer;
import flash.events.AccelerometerEvent;

var my_acc:Accelerometer = new Accelerometer();
my_acc.setRequestedUpdateInterval(50);

//my_txt.text = “Acc support is “+Accelerometer.isSupported;

my_acc.addEventListener(AccelerometerEvent.UPDATE, onAccUpdate);
function onAccUpdate(e:AccelerometerEvent):void{
ball.x -= (e.accelerationX*10);
ball.y += (e.accelerationY*10);

if (ball.x stage.stageWidth) {
ball.x = stage.stageWidth;
}

if (ball.y stage.stageHeight)
{ ball.y = stage.stageHeight;
}

}

This is a simple application that has a ball moving in the direction that the phone is tilting. You can test the application by downloading it below.

Download Android Air Application

I am not liable to damage it may cause to your phone. Use at your own risk.

I tried it on my phone, so their should be no problem.


Follow

Get every new post delivered to your Inbox.