Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Actionscript 3 and AIR - FileStream

New Here ,
May 03, 2009 May 03, 2009

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.

TOPICS
ActionScript
2.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 03, 2009 May 03, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2009 May 03, 2009

hola, estoy usando flash cs3... y gracias por la sugerencia, me confundí en las opciones del editor de este foro

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 03, 2009 May 03, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 03, 2009 May 03, 2009

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 03, 2009 May 03, 2009

Me parece que documentLocalPath tiene esa info dentro de la referencia que haces a File.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 03, 2009 May 03, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 04, 2009 May 04, 2009

Thanks michael and Muzak

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2009 May 31, 2009
LATEST

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.

TitleGiven_NameSurnameGongSalutationPositionOrganisationAddress_Line_1Address_Line_2Address_Line_3SuburbStatePostcodeCountryHome_PhoneFaxOther_PhoneUser_Field_1User_Field_2User_Field_3User_Field_4Mobile_PhoneSecond_AddressSecond_Address_Line_1Second_Address_Line_2Second_Address_Line_3Second_SuburbSecond_StateSecond_CountrySecond_PostcodeLangcodeWebsite
Mr.JeffAlexanderRetention MarketingMonday, April 13th, 2009
Mr.AnthonyDemasoRetention MarketingMonday, April 13th, 2009
SallySwinamerYieldMonday, April 13th, 2009
ChrisTorbayYieldMonday, April 13th, 2009
AnnetteWarringGenesis VizeumMonday, April 13th, 2009
Mr.MarkKhouryGenesis VizeumMonday, April 13th, 2009
Mr.AndyThorndykeThorsonsMonday, April 13th, 2009
ShannonRutherfordCentral ReproductionsMonday, April 13th, 2009
Mr.RobGreenwoodCentral ReproductionsMonday, April 13th, 2009
LisaMarcheseDes RosiersMonday, April 13th, 2009
Mr.MichaelWhitcombeMcMillan LLPMonday, April 13th, 2009

Thanks,

Gill

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines