setting up FDT for Flex 4 SDK & Flash Player 10.1

Aiden Tailor wrote a great blog post on how to set up the Flex 4 SDK with FDT. You can check it out here

Read what he says, and follow the instructions, I did it and it works perfect, any problems just ask!

The point to this post is to take this one step more to configure the Flex 4 SDK to work with the Flash Player 10.1

Download Adobe Flash Player 10.1 beta 3 at Adobe Labs here

In the flex 4 SDK that you just set up from Aiden’s blog:

{SDKFolder}/frameworks/libs/player/10

replace the playerglobal.swc with the flash 10.1 that you just downloaded

open the flex-config.xml replace line 16 to read

 <target-player>10.1.0</target-player>

restart FDT

Now create a new project, “Flex 4 Test”
create a Main class

package {
	import flash.display.Sprite;
	import flash.events.AccelerometerEvent;
	import flash.sensors.Accelerometer;
	import flash.text.TextField;

	public class Main extends Sprite {
		private var myText:TextField = new TextField();
		private var acc:Accelerometer = new Accelerometer();
		private var isSupported:Boolean = Accelerometer.isSupported;

		public function Main() {
			myText.width = 200;
			addChild(myText);
			checksupport();
		}

		private function checksupport():void {
	    	if (isSupported) {
		    	myText.text = "Accelerometer feature supported";
			    acc.addEventListener(AccelerometerEvent.UPDATE, getInfo);
			} else {
			    myText.text = "Accelerometer feature not supported";

			}
		}

		private function getInfo(evt:AccelerometerEvent):void {
	    	myText.text = String("at: " + evt.timestamp + "n" + "acceleration X: " + evt.accelerationX + "n" + "acceleration Y: " +   evt.accelerationY + "n" + "acceleration Z: " + evt.accelerationZ);

		}
	}

}

Run file. I do get the following warning

This compilation unit did not have a factoryClass specified in Frame metadata to load the configured runtime shared libraries. To compile without runtime shared libraries either set the -static-link-runtime-shared-libraries option to true or remove the -runtime-shared-libraries option.

UPDATED
To fix this warning is an easy fix as it turns out, I had to search the flex-config.xml file to find it, but if you open the flex-config.xml file on line 385, you will see

<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>

make sure this property is set to true! it is set to false by default. This will get rid of the compiler warning when you run your projects using the Flex 4 SDK.

 

For some reason the text below in the swf file is very small, this is not the case! If you could like to see a version with larger text, lease go here.
The final swf
[kml_flashembed publishmethod=”static” fversion=”10.0.0″ movie=”http://blog.hawaiiflash.org/wp-content/uploads/2010/03/Main.swf” targetclass=”flashmovie”]

Get Adobe Flash player

[/kml_flashembed]

Linking buttons in AS 3

Since this is just a movie for a button, make the stage 100 px by 35 px, as we don’t need any more room that that for this button.

Create a Layer, called “visuals” this is where all the visuals will go, and will be the layer for the button.

drag a button on the the stage(window>common libraries>buttons) pick any button you like, and place it on the stage that you just created. If you double click the button, you can get into the movie clip so that you can create new text on the button. In the button movie clip you will see many layers, but you want to concentrate on the text layer. On this text layer, double click on the text on the button, and change the text. This is not necessary at all, but I doubt you want your button to say “Enter.” However, there are situations for this.

Give the button an instance name “visit_btn”

The reason why you want to use this instance name is so that you can communicate the button with actionscript.

create a new layer called “actions”, this is where all your actionsctipt you go. To get to the actions panel right click on this layer, and picks actions, or go to Window>Actions

Type the following code in the actions window


visit_btn.addEventListener(MouseEvent.CLICK, visit);

function visit(e:MouseEvent):void {

	var request:URLRequest=new URLRequest("http://hfug.net");

 	navigateToURL(request, "_self");

}

Here is my completed swf

[kml_flashembed fversion=”9.0.0″ movie=”http://hfug.net/wp-content/uploads/2010/03/myButton.swf” targetclass=”flashmovie” publishmethod=”static” width=”100″ height=”35″]

Get Adobe Flash player

[/kml_flashembed]

If you are un sure about any of this, please leave a comment, so I can help you through this. This post was motivated from a friend that says linking in actionscript 3 takes too much code, but as you can see it is straight forward, and very easy.