Posts Tagged Flash

Creating a Facebook Like Button in Flash Professional for Adobe AIR (1of2)

Download Demo Files (Start & Completed versions for Part 1 & Part 2) In order for the completed code to work you have to put in your Facebook App ID and generated Facebook Social Plugin code in the required fields.

I would also recommend publishing for Adobe AIR 2.6 or 2.7. I have not tested this with AIR 3.0.

The use of the Facebook Like Button in Flash has been pretty difficult to produce.  There have been some “work arounds” and “hacks”, but nothing as clear and direct as using the API’s from the  ActionScript 3 SDK for Facebook Platform .

Now the ActionScript 3 SDK for Facebook Platform currently DOES NOT have any API’s that allow you to create the “Like” button, but using some other ActionScript API’s and a Facebook’s Social Plugin we can incorporate the “Like Button”.

*Important note*

- This example is publishing for Adobe AIR and not the Flash Player for the web.
ActionScript 3 SDK for Facebook Platform currently does not have any API’s for the “Like Button”

There are two key components here to get started:

  1. Facebook Social Plugins - Facebook code snippets that allow you to incorporate Facebook social feature in your website without having to know any of the Facebook Graph APIs.
  2. Adobe AIR – HTMLLoader class - An Adobe AIR container that will display HTML content.

Create your “Like Button” Social Plugin

The Facebook Social Plugins allow you to quickly integrate your and/or other Facebook data into your HTML pages without having to know anything about the Graph API, FBML, etc.  We are going to use the Facebook Social Plugin (let Facebook do the dirty work) and then plug the code into our AIR app.

  1. Visit: http://developers.facebook.com/docs/reference/plugins/like-box/

    Facebook Social Plugin Custom Settings

  2. Fill in your desired fields. You can use any public Facebook Page URL for the URL section. (eg. myNOTO (shameless plug), Adobe, FlashPlatform, etc)
  3. Click the “Get Code” button
  4. Click on “HTML5” and copy both sections of code to a new Dreamweaver document or blank document.

    Facebook HTML5 Social Plugin

Create your HTML code 

In order for the code to display in the HTMLLoader object, it must be placed in HTML.

  1. Create a new HTML5 document.
  2. Paste the “<div>” tag elements after the “<body>” tag.
  3. Change all double quotes to single quotes. This will allow the code to be used as one String in Flash.
  4. Add “https:” in front of ” //connect.facebook.net

Facebook Social Plugin HTML

You can copy and paste the code below. Change YOUR_APP_ID to your Facebook Application ID.

<!DOCTYPE HTML><html><head><meta charset='UTF-8'><title>Untitled Document</title></head><body><div id='fb-root'></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0];if (d.getElementById(id)) {return;}js = d.createElement(s); js.id = id;js.src = 'https://connect.facebook.net/en_US/all.js#xfbml=1&appId=YOUR_APP_ID';fjs.parentNode.insertBefore(js, fjs);}(document, 'script', 'facebook-jssdk'));</script><div class='fb-like-box' data-href='https://www.facebook.com/myNOTO' data-width='292' data-show-faces='false' data-stream='false' data-header='false'></div></body></html>

Incorporate your “LIKE” button into Flash (AIR Application) Download Demo Files (Start & Completed versions for Part 1 & Part 2) 

  1. Open the file named “facebookNOTO.fla” from here.
  2. Save your file in your desired directory.
  3. You will notice: (these components will be used fully later in Part 2)
    1. UILoader
    2. Dynamic Text Field
    3. Text Area Component
    4. 5 buttons
  4. Create a Document class.  File -> New -> ActionScript File
  5. Save the file in the same directory as your “.fla” and name it ‘NotoFB.as“ and it is CASE SENSITIVE!!!

This file(NotoFB.as) will be used as our Document Class for the facebookNOTO.fla file.

Create your document class (NotoFB.as)

Create the package, class definition and constructor function

package{
	import flash.display.Sprite;
	
public class NotoFB extends Sprite{
public function NotoFB(){

  }
 }
}

Import the following classes that will be used in this example.
package{
	import flash.display.Sprite;
	
	import flash.html.HTMLLoader;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowType;
	import flash.net.URLLoader;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.events.MouseEvent;

public class NotoFB extends Sprite{
public function NotoFB(){

  }
 }
}

Define properties and initial values.  The added code creates a new instance of the HTMLLoader class and defines the options and boundaries for the HTMLLoader object.
package{
	import flash.display.Sprite;
	
	import flash.html.HTMLLoader;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowType;
	import flash.net.URLLoader;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.events.MouseEvent;

public class NotoFB extends Sprite{

	private var html:HTMLLoader;
	private var options:NativeWindowInitOptions;
	private var boundaries:Rectangle;

public function NotoFB(){

		html = new HTMLLoader();

		html.scrollV = 200;
		html.navigateInSystemBrowser = true;

		options = new NativeWindowInitOptions();
		options.type = NativeWindowType.NORMAL;
		boundaries = new Rectangle(950,55,300,300);

  }
 }
}

Create a function that will add the HTMLLoader object on the stage. Add the function the constructor function.
package{
	import flash.display.Sprite;
	
	import flash.html.HTMLLoader;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowType;
	import flash.net.URLLoader;
	import flash.geom.Rectangle;
	import flash.events.Event;
	import flash.events.MouseEvent;

public class NotoFB extends Sprite{

	private var html:HTMLLoader;
	private var options:NativeWindowInitOptions;
	private var boundaries:Rectangle;

public function NotoFB(){

		html = new HTMLLoader();

		html.scrollV = 200;
		html.navigateInSystemBrowser = true;

		options = new NativeWindowInitOptions();
		options.type = NativeWindowType.NORMAL;
		boundaries = new Rectangle(950,55,300,300);

		loadFacebookLikeButton();

}

        private function loadFacebookLikeButton():void {
        var myString:String = 'ADD YOUR HTML5 CODE FROM YOUR PASTED FACEBOOK SOCIAL';

	html = HTMLLoader.createRootWindow(false,options,false,boundaries);
	html.loadString(myString);
	addChild(html);
	html.width = 292;
	html.height = 60;
	html.x = 15;
	html.y = 0;

	html.addEventListener(Event.COMPLETE, completeHandler);

}
	private function completeHandler(event:Event):void {

			trace("Facebook Like Button Loaded");

  }
 }
}

Paste the code that you copied from the Facebook Social Plugin Page.
var myString:String = 'ADD YOUR HTML5 CODE FROM YOUR PASTED FACEBOOK SOCIAL';

After you paste your code, save your NotoFB.as file and return to Flash and set your class as the Document Class for your “.fla” file.

Document Class Properties Panel

 

Test your movie. You will see the “distractor” animation.  When you click on the “LIKE” button you will be prompted to log into Facebook.

 

Part 2 – Facebook Wall(post/read) in Flash Professional for Adobe AIR

 

Tags: , , , , , , , ,

The Document Class – Why is it so important? pt. 1

Through my travels as an instructor, I always get the question, What is a Document Class?  Well the answer is simple, but the possibilities are extreme.  During this article, I would like to explain some of the most important things to know about a Document Class….Mainly a Document Class is “Your SWF file”!

First of all, the document class is optional.  Ok, it’s 2011, most seasoned Flash Developers are NOT using the timeline anymore and are using the Document Class. And every year as someone reaches excellence, there is someone born…New to Flash/ActionScript. Someone, right now, is holding on to the timeline, as if their life depended on it. So, whatever category you may fall into, one thing is certain, Flash is OPEN to you.  Flash will let you do, pretty much, whatever you want.

  • Create animation and ActionScript on the timeline
  • Create animation without the timeline, using ActionScript
  • Create animation with AND without the timeline, together…

You do not have use a Document Class, but you should at least understand it.

One of the reasons why you should understand it:

  • 99% of all of the examples in the Adobe Help Docs, online articles and many books are written using a document class.

So, if you would like to leverage the power of “learn by example”, then you need to know, if nothing else, NOT how to WRITE a document class, but how to USE a document class.

So first things first, without getting too complicated.

  • Part 1. Two of the main uses of a Document Class
  • Part 2. Implement a Document Class.

Here are two of the most important topics when working with the document class?

  • Separate your code from the timeline
  • Let your SWF file become a Sprite vs a MovieClip

Separating your code from the timeline

I mentioned, the document class is optional.  You can have the same functionality with code running on the timeline and in the document class. The rule of thumb is if you want your ActionScript to be more portable, easier to update, and free from you FLA, then use a document class.  Take a look at the code below.

ActionScript on the Timeline inside of an FLA.
The ActionScript below draws a red circle on the stage with an x/y = 100 and radius = 50.

// DRAW A CIRCLE ON THE STAGE
var myCircle:Sprite = new Sprite();
myCircle.graphics.beginFill(0xFF0000);
myCircle.graphics.drawCircle(100, 100, 50);
addChild(myCircle);

ActionScript on in a Document Class.
The ActionScript below draws a red circle on the stage with an x/y = 100 and radius = 50.

package {

	import flash.display.Sprite;
	
	public class DCcode extends Sprite{
		
		public var myCircle:Sprite;

		public function DCcode() {
			// DRAW A CIRCLE ON THE STAGE
			myCircle = new Sprite();
			myCircle.graphics.beginFill(0xFF0000);
			myCircle.graphics.drawCircle(100, 100, 50);
			addChild(myCircle);

		}

	}

}

Both of the options above give us the same results.  As you see, there is more ActionScript that must be written in a Document Class, but it’s well worth the time. Next, I will discuss one of the benefits of using a Document Class.

Your SWF as a Sprite not a MovieClip

This may or may not be a surprise to you, but by default an SWF file is nothing more than a MovieClip.  Yes, that’s right, a MovieClip.  A MovieClip that contains other MovieClips, bitmaps, symbols, video, text, etc….  With that being said, a MovieClip is a very powerful symbol, actually, the most powerful symbol.  The thing that makes a MovieClip unique is the timeline.  The timeline allows you to create linear animations and also create linear dynamic functionality with ActionScript on keyframes.

Enter the Sprite Object.

The Sprite object, in all simple terms, can be considered a new symbol in Flash.  The only thing is that when you are converting a shape to a symbol, Sprite is not an option.  Your available options are, Graphic, Button, and MovieClip.  There are many ways to use Sprite objects in Flash, but our conversation here, is just focusing on the Document Class.

The main thing to remember about the Sprite Object/Symbol/Class is:

  • The Sprite is identical to the MovieClip. Except for one thing… The Sprite does NOT have a timeline.

In many cases, when we use MovieClips, we do not use the timeline in that MovieClip.  And in cases like these, the timeline is actually taking up unnecessary resources.  For this reason, Adobe created the Sprite class, to give us the ability to have the same power of the MovieClip, but not have to worry about the resources consumption that comes along with a MovieClip.

So now by using a Document Class, your SWF file can actually be a Sprite vs a MovieClip. Once again, look at the code below. On line 5, “extends Spite”, will make your SWF file become a Sprite.  Note: A Document Class can ONLY be a MovieClip or a Sprite.

package {

	import flash.display.Sprite;
	
	public class DCcode extends Sprite{
		
		public var myCircle:Sprite;

		public function DCcode() {
			// DRAW A CIRCLE ON THE STAGE
			myCircle = new Sprite();
			myCircle.graphics.beginFill(0xFF0000);
			myCircle.graphics.drawCircle(100, 100, 50);
			addChild(myCircle);

		}

	}

}

In part 2 of this article, I will discuss how to implement and use a Document Class.

Tags: , , ,

Using Flash Professional to create Apps for the BlackBerry Playbook

Update. This is a good option if you do not plan on using some the BlackBerry Playbook API’s. Great for games and projects that do not rely on deep integration of the API’s. Some, but not all of the API’s are suitable for Flash Pro.

Update @renaun Another good article on Building BlackBerry Playbook Apps here

As of now, the only “built-in” option to compiling Blackberry apps for the Blackberry Tablet is using Flash Builder 4. This process if straightforward, but what if you do not have Flash Builder 4 or if you have it and not comfortable using Flash Builder.  Let’s just say you are a Flash Professional Pro! During Adobe MAX, it was mentioned that Blackberry was working on an update for Flash Professional that will allow you to use Flash Pro to compile Blackberry Apps.  But, right now if you are only using Flash Professional then you are sort of “in the dark”.

Well, this tutorial will give you some insight on a workaround, until the update is released. First lets start with some basics.

  • Blackberry Apps have a “.bar” extension
  • SWF files are compiled to a “bar” file
  • You must use the Blackberry Tablet simulator
  • You must use VMware Fusion for MAC or VMware Player for Windows

Installing and configuring you computer to run the BlackBerry Tablet Simulator here

  1. Install the Blackberry Tablet OS SDK for Adobe AIR. here
  2. Install VMware Fusion for MAC or Windowshere
  3. Install/Configure the Blackberry Tablet simulator. here
  4. Enable Development Mode on the Blackberry Tablet simulator. here
  5. Retrive the IP address for the BlackBerry Tablet Simulator .  The IP addresss in the Simulator is used to transfer your BlackBerry App to the simulator. here

After the above steps are completed, you now can create and test your Apps on the BlackBerry tablet Simulator.

By default, our next steps would be to create a Flash Builder Project, compile and test it on the Simulator.  But we are going to use Flash Professional CS5.

Overview – The steps to create BlackBerry Apps using Flash Professional CS5.

  1. Create a new .fla file.
  2. Set the stage size to match the resolution of the BlackBerry Tablet. 1024 x 768
  3. Create you Flash project as normal.  Set your publish settings to Flash Player 10. (It is not necessary to set your Publish settings for AIR 2.5 or AIR for Android.  The xml files that are generated from these publish settings are not compatible with the BlackBerry Tablet/Simulator)
  4. Publish your project to create a “.swf” file.
  5. Create a Adobe AIR Application Descriptor File.  “appname-app.xml”.  You can download a template of the XML file here. Save the file in the same folder of your “swf” file. You will have to change a few of the tags to match the name of your application. These tags are in different areas within the xml file.
  6. <id>appName</id>
    <filename> appName </filename>
    <name> appName </name>
    <content>appName.swf</content>

  7. Create a folder called “icons” and create three “.png” files.
  8. Three sizes: 36 pixels, 48 pixels, and 72 pixels
  9. Name them: icon36.png, icon48.png, and icon72.png
  10. Using the command line, compile your application. Using Terminal on MAC or MS-DOS prompt on Windows.
  11. Navigate to the folder where your files are located.
  12. Run the following command, replace “appname” with the name of your application.

location_of_your_BlackBerrySDK/blackberry-airpackager -package appname.bar -installApp -launchApp appname -app.xml appname.swf icons/icon48.png icons/icon72.png icons/icon36.png -device IP_Address

The command will take your swf/xml/icons and compile it to a “.bar” file.  It will then install it on the BlackBerry Tablet Simulator and run your application.

Happy Developing! Flash Rocks!

Tags: , ,