Actionscript 3 如何获取要激活的功能,该功能将与

Actionscript 3 如何获取要激活的功能,该功能将与,actionscript-3,apache-flex,air,flex3,flexbuilder,Actionscript 3,Apache Flex,Air,Flex3,Flexbuilder,我有这个代码是我从一个外部XML文件的图像链接加载它与 <mx:Label id="textboxLink" text=""/> private function loadRemoteImg(url:String):void { textboxLink.text ..... loader, completeHandler etc. Save Image(), with ByteArray, JPEGEcoder and then to the location - files

我有这个代码是我从一个外部XML文件的图像链接加载它与

<mx:Label
id="textboxLink" text=""/>

private function loadRemoteImg(url:String):void { 

textboxLink.text
.....
loader, completeHandler etc.

Save Image(), with ByteArray, JPEGEcoder and then to the location - filestream etc.

私有函数loadRemoteImg(url:String):void{
textboxLink.text
.....
装载机、completeHandler等。
使用ByteArray、JPEG编码器保存图像(),然后保存到文件流等位置。
这一切都很好,但它是唯一可能的(由于据说Flash播放器10以后),由MouseeEvent这样的一个按钮点击

如前所述,它工作正常,但我真的需要在启动时激活它,就像在creationComplete中一样,否则


任何帮助或想法都将受到感谢!aktell

啊,对不起,我以为你只是想加载图像;我没有看到你也在试图保存它

对于以下两种情况,您都需要将图像作为二进制文件加载:

var urlLoader:URLLoader = new URLLoader(new URLRequest( myURL ));
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
...
这是因为如果我们正常加载它(使用
加载程序
),那么我们将得到一个
位图
对象,即Flash对图像的表示,而不是jpg/png数据本身。使用此方法加载它将在加载时为您提供一个
字节数组

如果您使用的是AIR,您应该能够使用
FileStream
类:

比如:

// NOTE: you can use any of the other File constants to get your path (e.g.
// documentsDirectory, desktopDirectory...
// myImageFileName is the name of your image, e.g. "myPic.jpg"
var file:File       = File.applicationStorageDirectory.resolvePath( myImageFileName );
var fs:FileStream   = new FileStream;
try
{
    fs.open( file, FileMode.WRITE );
    fs.writeBytes( imageBinaryData ); // imageBinaryData is a ByteArray
    fs.close();
}
catch ( e:Error )
{
    trace( "Can't save image: " + e.errorID + ": " + e.name + ": " + e.message );
}
如果您使用的是Flash,那么在不与用户交互的情况下保存数据的唯一方法是通过
共享对象
。这意味着您的数据在应用程序之外将不可用(它将是一个
.sol
文件),但根据您的操作方式,这可能不是问题

// get our shared object - if you're saving a lot of images, then you might need another shared
// object, whose name you know, that stores the names of the other images
var so:SharedObject = null;
try { so = SharedObject.getLocal( this.m_name ); }
catch ( e:Error )
{
    trace( "Couldn't get shared object: " + e.errorID + ": " + e.name + ": " + e.message );
    return;
}

// NOTE: it's possible you may need a registerClassAlias on the ByteArray before this
so.data["image"] = imageBinaryData;

// save the lso
try { so.flush( minDiskSpace ); }
catch ( e:Error )
{
    trace( "Couldn't save the lso: " + e.errorID + ": " + e.name + ": " + e.message );
}
要在以后实际使用图像,请加载文件(以二进制模式)/获取
SharedObject
,然后将保存的二进制文件转换为图像:

var l:Loader = new Loader;
l.contentLoaderInfo.addEventListener( Event.COMPLETE, this._onConvertComplete ); // you could probably also listen for the IO_ERROR event
try
{
    // NOTE: you can pass a LoaderContext to the loadBytes methods
    l.loadBytes( imageBinaryData );
}
catch( e:Error )
{
    trace( "Couldn't convert image: " + e.errorID + ": " + e.name + ": " + e.message );
}

...

// called when our loader has finished converting our image
private function _onConvertComplete( e:Event ):void
{
    // remove the event listeners
    var loaderInfo:LoaderInfo = ( e.target as LoaderInfo );
    loaderInfo.removeEventListener( Event.COMPLETE, this._onConvertComplete );

    // get our image
    var bitmap:Bitmap = loaderInfo.content;
    this.addChild( bitmap );
}

如果您不能使用这些方法中的任何一种,那么您必须进行某种用户交互(例如,鼠标单击)。(出于好奇,您是否尝试过只发送一个
MouseEvent。单击相关对象上的
,看看它是否有效?)

您如何加载图像?如果您只是从XML获取url,那么普通的
加载程序应该可以工作。鼠标单击限制通常仅用于打开url(
navigateToURL
)一切正常是的,它也是一个加载程序。问题是,它只能通过Btn单击激活!使用此选项。单击=“loadRemoteImage(textboxLink.text)".
textboxLink.text
只是一个带有url的标签。如何加载它完全取决于您自己-您刚刚选择了通过
单击
操作加载它;您可以很容易地让
计时器
设置间隔
,甚至是键盘事件来执行此操作;您只需在知道标签已被使用时调用它即可atedNO,一点也不,因为我已经尝试了一次&一次又一次,只需点击一个Btn就可以了。我发现的唯一一件事是提到Flash Player 10,如果它发生了变化,我知道这听起来很奇怪,但相信我,我尝试过任何东西,它总是会出现一个错误,即找不到URL鼠标:事件,但只有在没有用于btn点击!只是尝试了一个计时器建议!并没有发生任何事情没有错误消息,但它也没有激活