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 6691435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:05+00:00 2026-05-26T05:45:05+00:00

So I’m in the final stages of designing a game for the iPhone using

  • 0

So I’m in the final stages of designing a game for the iPhone using Flash CS5 and I’m running into a problem with it running on the iPhone. I am a registered Developer, so I’m doing this completely legit… I’m just doing it on a PC and with Flash so there are a few workarounds being done lol. I’m at a point where it runs perfectly in the simulator but not on the iPhone itself. I load up the game and the opening screen loads up where I have my PLAY button located. The problem is, it doesn’t work. It doesn’t click, change screens… nada. So I worked it out to be something I’m doing wrong with the way I’m using the Filesystem and my save game file. If I take out the filestream stuff and just put in hard values into all my save game variables, the game runs just fine. The PLAY button does its thing and the game is good to go, except of course that I’m stuck to just the hard set values instead of being able to do little things like change levels. So here is the code I’m using, and hopefully someone can see where I’ve gone wrong.

The app starts off with running a main.as which calls the saved game file…

private function addedMain(event:Event):void {
        //Set up opening screen
        gameStart = new GameStart(this);
        addChild(gameStart);
        //set up the save game info
        _savedGame = new SaveGameFile();
        _savedGame.initGame();
    }

gameStart runs a simple script that just has the title screen with a PLAY button. Clicking the PLAY button removes it and loads up the next screen. This is what isn’t working right now. The system may be just freezing or something, at this point I don’t have a way to tell exactly what’s happening except that the PLAY button does nothing. So the next thing called is the saved game file itself:

package  {
import flash.events.Event;
import flash.display.MovieClip;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.filesystem.File;
import flash.errors.IOError;

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

    public function SaveGameFile() {

    }

    public function initGame():void {
        file = File.applicationStorageDirectory;
        file = file.resolvePath("savedGame.xml");
        xmlLoad();
        initVariables();
    }

    private function xmlLoad():void {
        var fileStream:FileStream = new FileStream();
        try {
            fileStream.open(file, FileMode.READ);
        } catch(e:IOError) {
            createSaveFile();
            xmlSave();
        }
        var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
        savedGame = XML(str);
        fileStream.close();
    }

    public function saveTheGame():void {
        xmlSave();
    }

    private function xmlSave():void {
        var writeStream:FileStream = new FileStream();
        writeStream.open(file, FileMode.WRITE);
        var s:String = String(savedGame);
        writeStream.writeMultiByte(s, File.systemCharset);
        writeStream.close();
    }

    private function createSaveFile():void {
        savedGame =
        <savedGame>
            <levelsCompleted>0</levelsCompleted>
            <levelWorkingOn>0</levelWorkingOn>
            <volLevel>0.05</volLevel>
            <sfxLevel>0.75</sfxLevel>
            <level>
                <levelNum>1</levelNum>
                <highScore>0</highScore> //...etc.
            </level>
            //you get the idea
        </savedGame>
    }

So as you can see, I’m creating a XML file called savedGame (created the first time the game runs and then is just loaded when the game runs) and from that I’m pulling all my level information as needed and saving scores and such. Again this is working just fine in the simulator (of course) but if I leave this code in, I don’t get past the starting page. So does anything jump out to anyone as to why this isn’t working? Help! Thanks 😉

  • 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-26T05:45:06+00:00Added an answer on May 26, 2026 at 5:45 am

    UPDATE: So I may have been on the wrong track all along because through messing around with my file on my computer I was finally able to see the error occur where I could easily trace problems compared to tracing on the iPhone. I don’t know if my original code was flawed or not, however, I do know that this code below works perfectly, so I’m keeping it (and I like it better anyway). HOWEVER, my main problem seems to have been the fact that I’m using XML as my save file. This is perfectly fine to do, BUT for some reason, saving the file causes a couple of strange characters to be entered at the very beginning of the file. So instead of starting

    <savedGame>
    

    it was starting with something like

    |Y<savedGame>
    

    The | was actually a symbol I couldn’t find that had a line in the middle and a charCode of 25 and the Y was actually a Yen sign. So whatever that was, it was causing me to get a 1088 Error. I solved this by striping any and all characters (whatever they end up being just in case it’s different for everyone… not sure if it is but not taking any chances). So in my code below I added a section between //EDIT START and //EDIT STOP that is only needed if you too are using XML in your script. Otherwise you can leave this out. Hope this helps 🙂

    ORIGINAL POST: OK so it seems that through some messing around with the code listed at the bottom of the page linked by danii, I was able to get that sites code working after all. I’m tempted to look back at my original code and mess with it to see if I can get it to work with what I’ve learned from this, but the game is working so I’m moving on and never looking back… lol. What I did find out though is that for my needs, that pages code was not quite workable (and why I gave up on it originally). It might have worked for their needs, but unless you package the game with a file, as far as I can tell their function “getSaveStream” will always return ‘null’ because the file will never be able to be written. So I removed a lot of their if’s and try’s because they were causing the game to fail. Here is what I ended up with in the context of my original post:

    package  {
        import flash.events.Event;
        import flash.display.MovieClip;
        import flash.filesystem.FileMode;
        import flash.filesystem.FileStream;
        import flash.filesystem.File;
        import flash.errors.IOError;
    
        public class SaveGameFile extends MovieClip {
            private var f:File;
            private var savedGame:XML;
    
            public function SaveGameFile() {
    
            }
    
            public function initGame():void {
                xmlLoad();
                initVariables();
            }
    
            private function getSaveStream(write:Boolean, sync:Boolean = true):FileStream {
                // The data file lives in the app storage directory, per iPhone guidelines.
                f = File.applicationStorageDirectory.resolvePath("savedGame.xml");
    
                // Try creating and opening the stream.
                var fs:FileStream = new FileStream();
                try {
                    //write is True and writing asynchronously.
                    if(write && !sync) {
                        fs.openAsync(f, FileMode.WRITE);
                    } else {
                        //For synchronous write, or all reads, open synchronously.
                        fs.open(f, write ? FileMode.WRITE : FileMode.READ);
                    }
                } catch(e:Error) {
                    // On error return null.
                    return null;
                }
                return fs;
            }
    
            private function xmlLoad():void {
                var fs:FileStream = getSaveStream(false);
                if(fs) {
                    var str:String = fs.readMultiByte(f.size, File.systemCharset);
                    //EDIT START
                    //check for "bad characters" at the start of the XML file
                    var badCharCheck = str.charCodeAt(0);
                    //the first char MUST be '<' which has a CharCode of 60
                    while(badCharCheck != 60) {
                        //if the first character isn't '<' then remove it
                        str = str.replace(String.fromCharCode(badCharCheck), "") ;
                        //recheck the first character
                        badCharCheck = str.charCodeAt(0);
                    }
                    //EDIT END
                    savedGame = XML(str);
                    fs.close();
                } else {
                //fs returned null so create the XML file savedGame and save it
                    createSaveFile();
                    xmlSave();
                }
            }
    
            public function saveTheGame():void {
                //this is used to call the save function externally
                xmlSave();
            }
    
            private function xmlSave():void {
                //the file exists because it was created with FileMode.WRITE in getSaveStream
                var fs:FileStream = getSaveStream(true, false);
                var s:String = String(savedGame);
                fs.writeUTF(s);
                fs.close();
            }
    
            private function createSaveFile():void {
                //this is only called the very first time the game is run on the iPhone
                savedGame =
                    <savedGame>
                        <levelsCompleted>0</levelsCompleted>
                        <levelWorkingOn>0</levelWorkingOn>
                        <volLevel>0.05</volLevel>
                        <sfxLevel>0.75</sfxLevel>
                        <level>
                            <levelNum>1</levelNum>
                            <highScore>0</highScore> //...etc.
                        </level>
                        //you get the idea
                    </savedGame>
            }
    

    So I’m happy to say it tested perfectly and is now running and saving information like it is supposed to. Hope this is of use to someone who runs into the same issue I did. Happy coding!

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.