The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • AIR
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 AIR

  • mit_51 Author 
    • 13809 
    • 0 
    • 14 
    AIR in Flash CS3 save text input to file
    ravipchandra

    Last reply Feb 28 2009, 10:23 AM

    by ravipchandra

    Posted: Jun 06 2008, 11:03 AM

    by mit_51

     

Hi,

I’m working on a simple AIR (Building in Flash CS3) application and was wondering if some one on this forum could help me with a solution. I have like 4 text input fields that will collect user input and I’d like to save the data to a text file. Any help would be much appreciated.

Cheers

Mit

  14 REPLIES
 
Nutrox
1  
Nutrox

Here is an example of how to write a simple text file…

[highlight=ActionScript 3.0]import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

// Create a file.
// For this example the file will be created on the desktop.
var file:File = File.desktopDirectory.resolvePath( “my-new-file.txt” );

// Create a file stream to write stuff to the file.
var stream:FileStream = new FileStream();

// Open the file stream.
stream.open( file, FileMode.WRITE );

// Write stuff to the file.
stream.writeUTFBytes( “Hello. This is some text in a file.” );

// Close the file stream.
stream.close();

// Clean up.
file = null;
stream = null;[/highlight]
Getting the text values from TextFields should be easy enough for you. wink

  • 06 June 2008 11:01 PM
  •  
mit_51 Author 
2  
mit_51

Hey Nutrox, alright there. Thanks for the code. Will have a crack at it later today.

Cheers

  • 09 June 2008 02:51 AM
  •  
mit_51 Author 
3  
mit_51

Hi Nutrox, Just tried the code. I’m sure it’s right having looked at the file api but I’m getting a 1046 error (type was not found or was not a compile-time constant). Is this down to how the file stuff is imported at the top?

Cheers

  • 09 June 2008 07:57 AM
  •  
Nutrox
4  
Nutrox

I think that is probably the cause of it. Flash doesn’t automatically import the flash.filesystem.* classes, so you need to do that manually.

  • 09 June 2008 08:03 AM
  •  
mit_51 Author 
5  
mit_51

Thanks for the quick response. I’ve added the path to the classes manually from the publish settings but that’s giving the same error. Is it added in a different way?

Thanks

  • 09 June 2008 08:30 AM
  •  
mit_51 Author 
6  
mit_51

I’ve tried different import rules and gone to the publish setting and changed the path and made sure that it points to the right classes folder. Still no luck I keep getting the 1046 error. I’d appreciate any help on this.

Cheers

  • 09 June 2008 11:09 AM
  •  
Nutrox
7  
Nutrox

Have you managed to publish any AIR SWF files before? It sounds strange that Flash should be moaning about those classes if you are importing them. Are you sure the problem isn’t somewhere else in your code?

confused

  • 09 June 2008 11:14 AM
  •  
mit_51 Author 
8  
mit_51

Yeah I’ve managed to publish air files before, based on tutorials and sample apps from adobe’s website. I know it is a bit wierd no one seems to be having this problem. I wonder if it needs to use the package { and then inside,

package {
    import flash
.filesystem.File;
    
import flash.filesystem.FileMode;
    
import flash.filesystem.FileStream;
    
    public class 
Main {
        
public var file:File = File.desktopDirectory.resolvePath( "my-new-file.txt" );
        public var 
stream:FileStream = new FileStream();
        
        public function 
Main(){
            stream
.open( file, FileMode.WRITE );
            
stream.writeUTFBytes( "Hello. This is some text in a file." );
            
stream.close();
            
file = null;
            
stream = null;
        
}
    }
} 

The 1046 error is gone, but now i’m getting a 5000 error saying the script must subclass. Completely lost frown

  • 09 June 2008 11:21 AM
  •  
Nutrox
9  
Nutrox

Ok, keep that class because that is the way you should be doing things. You have forgot to extend Sprite or MovieClip that is all, document/main classes need to extend one of those.

import flash.display.Sprite;

public class 
Main extends Sprite { 
  • 09 June 2008 11:25 AM
  •  
mit_51 Author 
10  
mit_51

Yeay thanks, I’ve got no errors now and it’s all working. Much appreciated and good learning experience.

Cheers

  • 09 June 2008 11:39 AM
  •  
ecm08
11  
ecm08

this overwrites whatever text is in my text file..how can i add to the file each time it is written to instead?

  • 29 July 2008 02:08 PM
  •  
Nutrox
12  
Nutrox

Change the file mode to “append”

stream.open( file, FileMode.APPEND ); 
  • 29 July 2008 02:42 PM
  •  
ecm08
13  
ecm08

thanks for the quick reply.

now i just need to figure out how to get the values of my username and email forms to save to the file rather than static text.

i tried:

var Email=Email;
stream.writeUTFBytes(Email);

  • 29 July 2008 03:56 PM
  •  
ravipchandra
14  
ravipchandra

Hi,

Could you please tell us how to import the flash.filesystem.* classes manually in flash cs3.


I am eagerly waiting for your reply
Chand

  • 28 February 2009 10:23 AM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 775  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,724  Assets
  • Profiles 282,659  Members
  • Topics 93,762  Topics
  • Blog 4  Blog
  • Facebook 1,680  Facebook
  • Twitter 1,165  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 04, 2012 - 19:28:34