Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6334617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:41:41+00:00 2026-05-24T18:41:41+00:00

I’m working on a flash game in Flash CS5 Professional that will eventually be

  • 0

I’m working on a flash game in Flash CS5 Professional that will eventually be running on an iPhone (hence the iOS tag). I am currently designing the save game portion of the code and I’m trying to set up what happens when someone runs the game for the very first time and the save game file doesn’t exist yet. Here is my code:

public class SaveGameFile extends MovieClip {
    private var file:File;
    private var savedGame:XML;

    public function SaveGameFile() {
        addEventListener(Event.ADDED_TO_STAGE, addedFileSystem);
    }

    private function addedFileSystem(event:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, addedFileSystem);
        file = File.applicationStorageDirectory;
        file = file.resolvePath("saveGame1.xml");
        xmlLoad();
    }

    private function xmlLoad():void {
        var fileStream:FileStream = new FileStream();
        fileStream.addEventListener(IOErrorEvent.IO_ERROR, ioReadErrorHandler);
        fileStream.open(file, FileMode.READ);
        fileStream.addEventListener(Event.COMPLETE, xmlLoadCompleteHandler);
    }

    private function xmlLoadCompleteHandler(event:Event):void {
        var fileStream:FileStream = event.target as FileStream;
        fileStream.removeEventListener(Event.COMPLETE, xmlLoadCompleteHandler);
        var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
        savedGame = XML(str);
        fileStream.close();
    }

    private function ioReadErrorHandler(event:Event):void {
        var fileStream:FileStream = event.target as FileStream;
        fileStream.removeEventListener(IOErrorEvent.IO_ERROR, ioReadErrorHandler);
        createFile();
        xmlSave();
    }

In the ioReadErrorHandler I have two more functions that basically create the XML file and put it into the savedGame variable. Then xmlSave creates the XML file. At least this is what is supposed to happen. Right now when it gets to

fileStream.open(file, FileMode.READ);

I get the Error #3003: File or directory does not exist, which means my ioReadErrorHandler isn’t doing the trick here. If I create the file and save it, then this code works perfectly and I can trace(savedGame) and it shows up just fine. But if I try to get it to create it (which as I mentioned it must when the game is first run) this is where I end up. Am I missing something here or is the IOErrorEvent.IO_ERROR not what I need to make this work?

Also once this is done (and working properly of course), will it go back to FileMode.READ and try again? Or does the error essentially break you out of the function and it needs to be run again?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:41:43+00:00Added an answer on May 24, 2026 at 6:41 pm

    As mentioned in the comment to my own post, I found the correct way to handle this synchronous operation. Here is the corrected code if anyone searching this wants to know:

    public class SaveGameFile extends MovieClip {
    private var file:File;
    private var savedGame:XML;
    
    public function SaveGameFile() {
        addEventListener(Event.ADDED_TO_STAGE, addedFileSystem);
    }
    
    private function addedFileSystem(event:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, addedFileSystem);
        file = File.applicationStorageDirectory;
        file = file.resolvePath("saveGame1.xml");
        xmlLoad();
    }
    
    private function xmlLoad():void {
        var fileStream:FileStream = new FileStream();
        try {
            fileStream.open(file, FileMode.READ); 
        } catch(e:IOError) {
            createFile();
            xmlSave();
        }
        var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
        savedGame = XML(str);
        fileStream.close();
    }
    

    Again “createFile():” runs a function that creates the XML file and saves it to the variable “savedGame”. Then “xmlSave();” runs a function to actually save the file so xmlLoad has something to load when this is run the very first time on a new device.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.