您加載ActionScript 3的圖像使用Loader
類:
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;
function loadImage(url:String):void
{
var l:Loader = new Loader();
var r:URLRequest = new URLRequest(url);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
l.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
l.load(r);
function onLoadError(e:IOErrorEvent):void
{
trace("Couldn't load image.");
e.target.removeEventListener(Event.COMPLETE, onLoadComplete);
e.target.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
}
function onLoadComplete(e:Event):void
{
trace("Load completed!");
e.target.removeEventListener(Event.COMPLETE, onLoadComplete);
e.target.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
stage.addChild(e.target.content); // e.target.content holds the loaded bitmap
}
}
UPDATE
您可以監聽與通話Javascipt使用回調和ExternalInterface
:
if(ExternalInterface.available) // check that SWF is running in a browser
ExternalInterface.addCallback("loadImage", loadImage);
然後,您可以使用對SWF的引用從Javascript調用該函數。例如,如果您的Flash嵌入這樣的:
var swf = document.getElementById("myFlash"); // get a reference
swf.loadImage(myURL); // call your AS3 function
更新1
我做了這個簡單:
<embed src="flash.swf" id="myFlash" width="800" height="600" />
可以使用JavaScript中的document.getElementById()
方法得到它的引用例如,您可以嘗試並瞭解我告訴您的內容:Download Example
請注意,這隻適用於Firefox,因爲我使用的嵌入標籤嵌入了Chrome,但如果嵌入正確,它可以跨瀏覽器使用。
來源
2013-07-11 06:47:46
Gio
而且..這和Java有什麼關係? 'Java'是'JavaScript','Car'是'地毯'。 –