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

  • Home
  • SEARCH
  • 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 643543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:17:39+00:00 2026-05-13T21:17:39+00:00

OK I am trying to make it so that when a user launches my

  • 0

OK I am trying to make it so that when a user launches my air app, it positions itself and sizes itself to whatever it was the last time it was opened.

Here is my code:

private function init():void
{
    gotoLastPosition();
    this.nativeWindow.addEventListener( Event.CLOSING, saveAppPosition );
}

private function saveAppPosition(e:Event = null):void
{
    var xml:XML = new XML('<position x="'+this.nativeWindow.x+'" y="'+this.nativeWindow.y+'" width="'+this.width+'" height="'+this.height+'"/>');

    var f:File = File.applicationStorageDirectory.resolvePath("appPosition.xml");
    var s:FileStream = new FileStream();
    try
    {
        s.open(f,flash.filesystem.FileMode.WRITE);

        s.writeUTFBytes(xml.toXMLString());

        s.close();
    }
    catch(e:Error){}
}

private function gotoLastPosition():void
{
    var f:File = File.applicationStorageDirectory.resolvePath("appPosition.xml");   
    if(f.exists)
    {
        var s:FileStream = new FileStream();
        s.open(f,flash.filesystem.FileMode.READ);
        var xml:XML = XML(s.readUTFBytes(s.bytesAvailable));

        this.nativeWindow.x = xml.@x;
        this.nativeWindow.y = xml.@y;
        this.width = xml.@width;
        this.height = xml.@height;
    }
}

This does work, however, I am getting complaints from users that sometimes when they launch the app, it is no where to be found (off screen), they can right click the taskbar item and maximize it to get it back, but that should not be necessary.

I can only assume this issue is caused by my attempt to save the position of the application. I do not know what could be going wrong tho, or how I can fix this?

Maybe a way to tell if the app is off-screen after positioning it, and move it on-screen if so? Don’t know how I can do that tho?

Any ideas?

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-13T21:17:40+00:00Added an answer on May 13, 2026 at 9:17 pm

    I believe you’ll want to change your XML saving code from:

    try
    {
        s.open(f,flash.filesystem.FileMode.WRITE);
    
        s.writeUTFBytes(xml.toXMLString());
    
        s.close();
    }
    catch(e:Error){}
    

    To

    try
    {
        s.open(f,flash.filesystem.FileMode.WRITE);
        s.writeUTFBytes(xml.toXMLString());
    } catch(e:Error) {
        logger.error( e );
    } finally {
        s.close();
    }
    

    If an error happens you’ll never see it since the catch block just ignores it. If an error is happening for some people the stream is never written to. Also the close call is never executed either so the file is left hanging open. Putting the close() call in the finally block will ensure regardless of success or failure the file will close. It’s not a guarantee that this is your problem, but these are, in theory, potential pitfalls some users might be experiencing.

    Also you might want to close the file after reading it too.

    var s:FileStream = new FileStream();
    try {
       s.open(f,flash.filesystem.FileMode.READ);
       var xml:XML = XML(s.readUTFBytes(s.bytesAvailable));
       ...
    } finally {
       s.close();
    }
    

    It’s possible that it fails to save the window location on exit because it can’t open the file for writing because it’s still open for reading too.

    I’d also recommend start writing these errors to a log file to see if an error could be the culprit. AIR has a pretty nice logging system that you can use very similar to log4j. When people are having trouble you can just get them to send you that log file and get better feedback about what’s going on in their program for their situation. Logging in any serious application is a must.

    Not to mention you can use applications like XPanelOnAIR to get logging messages as they happen during debugging. Much much much better than trace().

    http://www.novio.be/blog/?p=920

    http://livedocs.adobe.com/flex/3/html/help.html?content=logging_09.html

    Removed references to flush() since AIR doesn’t have those calls.

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

Sidebar

Related Questions

I am trying to make an app that opens android market page of selected
Basically I am trying to make a simple form that allows the user to
I'm trying to make an UI that contains a list of such items: http://img707.imageshack.us/img707/1114/16900293.png
I am just trying to make a timer. I would like to use UIDatePickerModeCountDownTimer
I am trying to build a twitter-like follow mechanism. User takes an action. We
I am trying to solve an issue sort of similar to what was done
I have been trying to configure a small website on a Windows Server 2008
I am making an autosuggesting function, when the user writes something in the field
So I am working on a bundle of applications for my company for the
I'm using the mock library written by Michael Foord to help with my testing

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.