var metrics : TextLineMetrics = _textfield.getLineMetrics(0);
_textfield.text = "Hello World";
_textfield.scaleY = -1;
_textfield.y = _textfield.textHeight + metrics.ascent + metrics.descent;
var metrics : TextLineMetrics = _textfield.getLineMetrics(0);
_textfield.text = "Hello World";
_textfield.scaleY = -1;
_textfield.y = _textfield.textHeight + metrics.ascent + metrics.descent;
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import flash.utils.Timer;
var loader:Loader = new Loader();
var timer:Timer;
//load the Flex Component
loader.load(new URLRequest("ButtonTest.swf"));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderDone);
addChild(loader);
function loaderDone(e:Event) {
timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, handleTimer)
timer.start();
}
function handleTimer(event:TimerEvent):void {
//cast the loader.content into MovieClip to access currentFrame.
var myclip:MovieClip = loader.content as MovieClip;
if (myclip.currentFrame == 2) {
//use application property to attach the event listener
myclip.application.addEventListener("iAmClickedFromFlex", clickedFromFlex);
timer.stop();
}
}
function clickedFromFlex(event:Event):void {
trace("clicked");
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button x="5" y="20" label="I am a flexbutton" click="dispatchEvent(new Event('iAmClickedFromFlex'))"/>
</mx:Application>
Here is an AIR demo that encapsulates some neat AIR and AS3 tricks.
It is called the Kevin Bacon Drag and Drop.
You have to drag an image file (jpg, png or gif) to the top of the screen.
When you drop the file it will fall down.
Make sure it lands on Kevin's camera and your picture will appear on the screen behind Kevin.
This a summary of all the features implemented in this demo:
1. compiled and written within Flash CS3 (not Flexbuilder)
2. the Adobe AIR drag and drop API
3. pixel perfect collision detection in AS3
4. the use of custom events and event bubbling
5. Ratio scaling for images
Thanks to Grant Skinner you can now compile AIR files from within Flash CS3.
Download and read the instructions here:
http://www.gskinner.com/blog/archives/2007/07/creating_air_pr.html
The Adobe AIR API documentation is build in the Flex3 Language reference (look for the classes with a blue dot next to them)
http://livedocs.adobe.com/labs/flex/3/langref/
Download the installer file here:
http://cases.boulevart.be/blogs/DragandDropGame.zip
Download the source files here:
http://cases.boulevart.be/blogs/DragandDropGame_source.zip
Here's a few mac and windows screenshots:
crossposted at labs.boulevart.be