Copy link to clipboard
Copied
Hi.
look at this actionscript code:
import flash.filesystem.*;
import flash.events.Event;
import flash.net.FileFilter;
var fileToOpen:File = new File();
var txtFilter:FileFilter = new FileFilter("Text", "*.as;*.css;*.html;*.txt;*.xml");
try
{
fileToOpen.browseForOpen("Open", [txtFilter]);
fileToOpen.addEventListener(Event.SELECT, fileSelected);
}
catch (error:Error)
{
trace("Failed:", error.message);
}
function fileSelected(event:Event):void
{
var stream:FileStream = new FileStream();
stream.open(event.target, FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
trace(fileData);
}
The function fileSelected causes the error: 1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.filesystem:File. ... exactly this line:
stream.open(event.target, FileMode.READ);
I got it from: http://help.adobe.com/es_ES/AS3LCR/Flash_10.0/flash/filesystem/File.html#browseForOpen()
Thanks for the help.
Copy link to clipboard
Copied
Hola estas usando Flash Cs3 o Cs4 para la autoria de esta aplicacion AIR? Una pequeña recomendacion la proxima vez que quieras publicar codigo insertalo como codigo de JAVA para que se pueda leer mas facilmente, leer el codigo que enviaste antes es imposible en esa forma.
Copy link to clipboard
Copied
hola, estoy usando flash cs3... y gracias por la sugerencia, me confundí en las opciones del editor de este foro
Copy link to clipboard
Copied
En todo caso al codigo de la ayuda le falta algo agregalo asi y funcionara
import flash.filesystem.*;
import flash.events.Event;
import flash.net.FileFilter;
private var fileToOpen:File = new File();
private var txtFilter:FileFilter = new FileFilter("Text", "*.as;*.css;*.html;*.txt;*.xml");
private function fileOpen():void{
try
{
fileToOpen.browseForOpen("Open", [txtFilter]);
fileToOpen.addEventListener(Event.SELECT, fileSelected);
}
catch (error:Error)
{
trace("Failed:", error.message);
}
}
private function fileSelected(event:Event):void
{
var stream:FileStream = new FileStream();
stream.open(File(event.target), FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
trace(fileData);
}
No te preocupes el foro es relativamente nuevo para la mayoria.
Copy link to clipboard
Copied
Gracias por tu ayuda, ahora funciona... solo una ultima pregunta ¿sabes cual es el metodo para capturar la ruta del archivo seleccionado en el cuadro de dialogo?
Copy link to clipboard
Copied
Me parece que documentLocalPath tiene esa info dentro de la referencia que haces a File.
Copy link to clipboard
Copied
You have to cast the target to File as evt.target and evt.currentTarget are typed as Object.
And use currentTarget instead of target (see docs)
stream.open(event.currentTarget as File, FileMode.READ);
and erhm, keep it English in here please.
Copy link to clipboard
Copied
Thanks michael and Muzak
Copy link to clipboard
Copied
Hi,
Wondering if someone helped you. I want to open xsl or csv file and using below code
var file:File = evt.currentTarget as File;
file = file.resolvePath(file.nativePath);
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var fileData:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
var endings:Array = [File.lineEnding, "\n", "\r"];
but for some reason it return "ÐÏ ࡱ á" funny value. Any idea why don't i get the correct data from file.
belwo is the csv file i am trying to open.
| Title | Given_Name | Surname | Gong | Salutation | Position | Organisation | Address_Line_1 | Address_Line_2 | Address_Line_3 | Suburb | State | Postcode | Country | Home_Phone | Fax | Other_Phone | User_Field_1 | User_Field_2 | User_Field_3 | User_Field_4 | Mobile_Phone | Second_Address | Second_Address_Line_1 | Second_Address_Line_2 | Second_Address_Line_3 | Second_Suburb | Second_State | Second_Country | Second_Postcode | Langcode | Website |
| Mr. | Jeff | Alexander | Retention Marketing | Monday, April 13th, 2009 | |||||||||||||||||||||||||||
| Mr. | Anthony | Demaso | Retention Marketing | Monday, April 13th, 2009 | |||||||||||||||||||||||||||
| Sally | Swinamer | Yield | Monday, April 13th, 2009 | ||||||||||||||||||||||||||||
| Chris | Torbay | Yield | Monday, April 13th, 2009 | ||||||||||||||||||||||||||||
| Annette | Warring | Genesis Vizeum | Monday, April 13th, 2009 | ||||||||||||||||||||||||||||
| Mr. | Mark | Khoury | Genesis Vizeum | Monday, April 13th, 2009 | |||||||||||||||||||||||||||
| Mr. | Andy | Thorndyke | Thorsons | Monday, April 13th, 2009 | |||||||||||||||||||||||||||
| Shannon | Rutherford | Central Reproductions | Monday, April 13th, 2009 | ||||||||||||||||||||||||||||
| Mr. | Rob | Greenwood | Central Reproductions | Monday, April 13th, 2009 | |||||||||||||||||||||||||||
| Lisa | Marchese | Des Rosiers | Monday, April 13th, 2009 | ||||||||||||||||||||||||||||
| Mr. | Michael | Whitcombe | McMillan LLP | Monday, April 13th, 2009 | |||||||||||||||||||||||||||
Thanks,
Gill
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more