2014-03-01 8 views
0

와 함께 사용할 수, 표준되는 활성화하는 기능을 가져 오는 방법을 이미지의 링크는이 모든 일내가이 외부 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. 

... 그것을로드 좋아, 그럼에도 불구하고 MouseEvent에 의해서만 (Flash Player 10 이후 버전으로 인해) 버튼 클릭 만 가능합니다!

언급했듯이 모든 항목이 제대로 작동하지만 실제로는 creationComplete 또는 기타와 같이 시작할 때 활성화해야합니다.

어떤 도움이나 아이디어라도 도움이 될 것입니다. 안부 aktell

+0

어떻게 이미지를로드하나요? XML로부터 URL을 얻는다면 정상적인'Loader'가 작동 할 것입니다. 마우스 클릭 제한은 일반적으로 URL 열기 ('navigateToURL')에만 해당합니다. – divillysausages

+0

모든 것이 YES로 작동하며, 로더이기도하지만 문제는 Btn 클릭만으로 활성화된다는 것입니다! 이것을 사용하십시오. click = "loadRemoteImage (textboxLink.text)". – aktell

+0

'textboxLink.text'는 URL이 포함 된 레이블 일뿐입니다. 로드하는 방법은 전적으로 당신에게 달렸습니다 - 당신은 방금'click' 액션으로로드하도록 선택했습니다; 'Timer','setInterval' 또는 키보드 이벤트를 쉽게 할 수 있습니다. 그 레이블을 채웠다는 것을 알 때 그냥 호출해야합니다. – divillysausages

답변

0

아, 죄송 합니다만, 나는 당신이 이미지를로드하려하고 있다고 생각했습니다. 나는 네가 그것을 구하려고 시도하는 것을 보지 못했다. 다음과 같은 경우 모두에 대한

, 당신은 바이너리로 이미지를로드해야합니다 : 우리는 (A Loader 사용) 일반적으로로드하는 경우, 우리는거야 무엇

var urlLoader:URLLoader = new URLLoader(new URLRequest(myURL)); 
urlLoader.dataFormat = URLLoaderDataFormat.BINARY; 
... 

이 있기 때문에 Bitmap 개체 (예 : jpg/png 데이터 자체가 아닌 이미지의 플래시 표현). 이 방법을 사용하여로드하면 ByteArray이로드됩니다.

는 AIR를 사용하는 경우, 당신은 FileStream 클래스 사용할 수 있어야합니다 : http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html

뭔가 같은 : Flash를 사용하는 경우

// 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); 
} 

을 다음 유일한 방법은 절약 할 수 있습니다 사용자 상호 작용이없는 항목은 SharedObject입니다. 이는 데이터가 앱 외부에서 사용 가능하지 않음을 의미합니다 (이 파일은 .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.CLICK을 파견하려고 했습니까?)