<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
preinitialize="{initJSInterface()}"
creationComplete="{creationCompleteHandler(event)}">
<mx:Script>
<![CDATA[
import flash.utils.setInterval;
import aw.external.JSInterface;
// Embed jQuery library into Flex application
[Embed(source="jquery-1.2.6.js",mimeType="application/octet-stream")]
static private const J_QUERY_SCRIPT:Class;
protected function initJSInterface():void{
JSInterface.initialize();
// Get embeded code as text
var data:ByteArray = new J_QUERY_SCRIPT();
data.position = 0;
// Insert jQuery into HTML as virtual - without creating <SCRIPT> container
JSInterface.pushJavaScript(data.readUTFBytes(data.length), '', true);
}
private var $:Function;
protected function creationCompleteHandler(event:Event):void{
// Now you can use jQuery through JSInterface or ExternalInterface
$ = JSInterface.window.$;
trace($('body'));
trace($('embed')[0].src);
}
]]>
</mx:Script>
</mx:Application>