Don't know whether I'm posting this in the right place, but here it goes. I'm relatively new to Flash, and I'm currently working on an Air app in Flash CS5, which displays my site trough HTMLLoader. I'm having a small problem at the login page. What I want to be able to do is log in through the app, and have it remember my username and password, so that it will automatically log me in the next time I open the app. My login has one of those "remember me" check boxes, which is supposed to remember the login details. The problem is when I close the app down, it doesn't store my username and password, so when I reopen it, it just gives me a blank login screen again. How can I fix this?
Another problem is what happens if the internet cuts out. I've added code into the app, which displays an error message if there's no internet connection, but if the internet cuts out while using the app, it just displays the error message over the site, but everything is still active under it. Is there a way to "kill" HTMLLoader when there's no internet, then have it reopen when it reconnects?
Thanks in advance.
how are you storing the username/password?
you can monitor the user's internet connection: http://magicwithflex.wordpress.com/2009/11/23/monitor-the-availabilty- of-internet-connection-for-an-air-application/
For the latter, disabling the content in HTMLLoader, use the mouseChildren standard boolean, e.g.:
myHTMLLoader.mouseChildren = false;
That should disable anything inside from responding to the mouse until you re-enable it.
As for saving the username/password, that's up to you to handle in a few ways. You really should use ExternalInterface and communicate with JavaScript to set up a session. Storing username/password in plain text in a cookie is a bad idea (which is another way). You typically log a person in, generate a key server-side (sometimes called a session) and store that in a cookie. If you have a key when the app is loaded, it's sent to the server, validated, and then auto-logs in the user.
Just adding a checkbox, calling it "Remember Me" does not add the programming involved to make it function.
Sorry for bothering you, but I've just tried to use mouseChildren with my code, but I can't get it to work. Here's my code. What am I doing wrong? (probably a total noob mistake)
import air.net.*;
import air.net.URLMonitor;
import flash.net.URLRequest;
import flash.events.StatusEvent;
var monitor:URLMonitor = new URLMonitor(new URLRequest("http://www.google.com"));
monitor.addEventListener(StatusEvent.STATUS, checkHTTP);
monitor.start();
function checkHTTP(e:StatusEvent) {
if (monitor.available) {
var htmlL:HTMLLoader=new HTMLLoader();
htmlL.width=1200;
htmlL.height=662;
htmlL.x=0;
htmlL.y=38;
addChild(htmlL);
htmlL.load(new URLRequest("http://www.google.com"));
} else {
htmlL.mouseChildren = false;
}
}
// must be defined outside the function or
// when you create htmlL ONLY if monitor.available
// can you actually use htmlL. Otherwise it doesn't exist.
// So make it exist in both situations.
var htmlL:HTMLLoader;
function checkHTTP(e:StatusEvent)
{
if (monitor.available)
{
htmlL= new HTMLLoader();
htmlL.width=1200;
htmlL.height=662;
htmlL.x=0;
htmlL.y=38;
addChild(htmlL);
htmlL.load(new URLRequest("http://www.google.com"));
}
else
{
if (htmlL)
{
htmlL.mouseChildren = false;
htmlL.mouseEnabled = false;
}
}
}
Thank you! It's working great, just one more question (really sorry for this), how would I get the app to redirect to another frame, when It detects no internet from startup, and when the internet cuts out during usage? Here's my code, but I can't get it to work:
if (monitor.available)
{
htmlL= new HTMLLoader();
htmlL.width=1200;
htmlL.height=662;
htmlL.x=0;
htmlL.y=38;
addChild(htmlL);
htmlL.load(new URLRequest("http://www.google.com"));
}
else
{
gotoAndStop (13);
if (htmlL)
{
htmlL.mouseChildren = false;
htmlL.mouseEnabled = false;
gotoAndStop (13);
}
}
}
Kglad linked a tutorial in post #1 for this already.
Here's the URLMonitor on livedocs, a class to monitor internet connectivity and fire events based on it:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/air /net/URLMonitor.html
HTTP monitoring example (because you can monitor more than just HTTP):
The examples are pretty much cut and paste. Pay attention to the events and do whatever you wish based on what it reports.
North America
Europe, Middle East and Africa
Asia Pacific