FlashPlayer10
FileReference類別功能越來越強大
Player9只能upload
現在可以直接讀取本機的檔案
或是另存成一個新的格式,
這次就來練習開啟本機.txt檔, 編輯完在另存成一個新的.txt
FileReference類別功能越來越強大
Player9只能upload
現在可以直接讀取本機的檔案
或是另存成一個新的格式,
這次就來練習開啟本機.txt檔, 編輯完在另存成一個新的.txt
package { import flash.display.*; import flash.events.*; import flash.geom.Rectangle; import flash.text.*; import flash.net.*; import flash.utils.ByteArray; import flash.utils.getTimer; [SWF(width = "600", height = "400", backgroundColor = "#FFFFFF", framerate = "30")] public class FileLoad extends Sprite { private var _fileRef:FileReference; private var it:TextField; public function FileLoad() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; it = new TextField(); it.width = 500; it.height = 300; it.border = true; it.multiline = true; it.type = "input"; it.y = 35; addChild(it); var qb1:QuickButton = new QuickButton("Load File"); qb1.addEventListener(MouseEvent.CLICK, fileLoadHandler); addChild(qb1); var qb2:QuickButton = new QuickButton("Save File"); qb2.x = 105; this.addChild(qb2); qb2.addEventListener(MouseEvent.CLICK, fileSaveHandler); _fileRef = new FileReference(); _fileRef.addEventListener(Event.SELECT, fileSelectHandler); _fileRef.addEventListener(Event.COMPLETE, fileCompleteHandler); } private function fileLoadHandler(e:Event):void { _fileRef.browse([new FileFilter("text Formats (*.txt)", "*.txt;*.TXT", "txt")]); } private function fileSaveHandler(e:Event):void { var _fileRefSave:FileReference = new FileReference(); _fileRefSave.save(it.text, getTimer() + ".txt"); //Flash Player10 FileReference新方法 save。 } private function fileSelectHandler(e:Event):void { _fileRef.load(); //Flash Player10 FileReference新方法 load。 } private function fileCompleteHandler(e:Event):void { it.text = _fileRef.data.readUTFBytes(_fileRef.data.length); } } } import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; internal class QuickButton extends Sprite { public function QuickButton(pString:String):void { this.buttonMode = true; this.mouseChildren = false; graphics.beginFill(0xCCCCCC); graphics.drawRect(0, 0, 100, 30); var tf:TextField = new TextField(); tf.y = 5; var format:TextFormat = new TextFormat(); format.font = "Verdana"; format.color = 0x000000; format.size = 12; format.align = "center"; tf.defaultTextFormat = format; tf.selectable = false; tf.text = pString; tf.width = 100; tf.height = 30; addChild(tf); } }
留言
小弟一直想用flash作出檔案輸出與輸入的效果,始終摸不著頭緒,甚至用到AIR才成功,不過大大功力更神,小弟佩服~~
感謝~~
我的EMAIL:s923348@yahoo.com.tw