2013-03-14 75 views
0

無法獲取我的文件大小!我有一個變量加載文件,然後在我的fileCompleteLoad事件我想檢查該文件(.png)的大小。通過文件變量類型從加載的文件獲取大小ActionScript3

// clickButton event to load the file

public function onMouseClick(e:MouseEvent):void{ 
    _fileRef = new File(); 
    _fileRef.addEventListener(Event.SELECT, onFileSelected, false, 0, true); 
    _fileRef.addEventListener(Event.CANCEL, onCancel, false, 0, true); 
    _fileRef.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); 
    _fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, 
    onSecurityError, false, 0, true); 

    _fileRef.browse([_imageFilter]); 
} 

// selected event 

public function onFileSelected(evt:Event):void 
{ 
    _fileRef.addEventListener(ProgressEvent.PROGRESS, onProgress, false, 0, true); 
    _fileRef.addEventListener(Event.COMPLETE, onComplete, false, 0, true); 
    _fileRef.load(); 
} 


// thats my eventComplete 

public function onComplete(evt:Event):void 
{ 
    _msgSuccessErrorTextField.text = "File was successfully loaded."; 
    _pngInputTextField.text = String(_fileRef.nativePath); 
    _atfOutputTextField.text = _fileRef.nativePath.replace(".png",".atf"); 
    _inputNativeProcess = _fileRef.nativePath; 
    _outputNativeProcess = _atfOutputTextField.text; 
    _flagLoadedFile = new Boolean(true); 

    var test:Bitmap = evt.target.data as Bitmap; 
    if(test){ 
     trace(test.height); 
    } 

    _fileRef.removeEventListener(Event.SELECT, onFileSelected); 
    _fileRef.removeEventListener(ProgressEvent.PROGRESS, onProgress); 
    _fileRef.removeEventListener(Event.COMPLETE, onComplete); 
    _fileRef.removeEventListener(Event.CANCEL, onCancel);  

現在,在這種情況下我想檢查我的文件大小......我試過很多東西,但沒有得到成功......有時我得到空從我_fileRef.data。

任何建議來解決這個問題?

THX

回答

0

的答案是 -

//添加我的公共職能的onComplete(EVT:事件):無效{}

var loader:Loader = new Loader(); 

loader.loadBytes(byteArray); 

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete); 

// build another event 

publicfunction loaderComplete(event:Event):void 
{ 
var loaderInfo:LoaderInfo = LoaderInfo(event.target); 

var bitmapData:BitmapData = new BitmapData(loaderInfo.width, 
loaderInfo.height, false, 0xFFFFFF); 

bitmapData.draw(loaderInfo.loader); 
// result: bitmapData 

}

現在我可以得到高度,witdh什麼...... thx!

2

只是爲了確保,你得到了onComplete處理程序中的data?您顯示的代碼現在不會這樣做。應該是這樣的:

_fileRef.addEventListener(Event.COMPLETE, onComplete, false, 0, true); 

private function onComplete(e:Event):void 
{ 
    var test:Bitmap = e.target.data as Bitmap; 
    if(test) 
     trace(test.height); 
} 
+0

我做了你說的,但仍然沒有工作......它說我的測試:位圖正在接收NULL,而不是實際上文件。我用我的活動編輯我的問題。看看 – RafaelFelisbino 2013-03-14 15:32:38

+0

「e.target」和「e.target.data」的類型是什麼? e.target.data'是否也是NULL? – 2013-03-14 15:38:55

+0

'_browsePngTextFiledButton.addEventListener(MouseEvent.MOUSE_DOWN,onMouseClick,false,0,true);' – RafaelFelisbino 2013-03-14 15:42:59