Properties not being saved?

Hello. I'm incredibly new to ActionScript and to making widgets. I need some help with my widget's code. What it does is ask for a url and then at runtime checks that url to see if the password entered is valid. If yes, success. If no, failure.
I've gotten it to work with a hard-coded url in it but I thought the widget would be more useful if the widget could be configured for a url.
I think what's going wrong is the properties aren't saving.
The AS code is below. I can provide the FLA if needed.

//Widget created by Randy Walker

package
{

import widgetfactory.InteractiveWidget;
import widgetfactory.events.WidgetEvent;
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;

public class passwordProtect extends InteractiveWidget
{

private var textFieldDefaultText:String = "http://";

override protected function enterPropertiesDialog ():void
{
gotoAndStop(2);

checkProperties();

rwURL.text = properties.textFieldText;
}

private function checkProperties():void
{
if (properties.setBefore == true)
{
textFieldDefaultText = properties.textFieldText;

}
}

override protected function saveProperties ():void
{
properties.textFieldText = rwURL.text;
properties.setBefore = true;

}

override protected function enterStage ():void
{
gotoAndStop(3);
}

override protected function enterRuntime():void
{
gotoAndStop(1);

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.showDefaultContextMenu = false;

//path to the remote file on your server
var remotePath:String = properties.textFieldText;

login.addEventListener(MouseEvent.MOUSE_DOWN, loginDown);

function loginDown(e:MouseEvent):void
{
hideHint();
//check to see if something in the pass text field
if (rwPassword.text != "")
{
sendLoadData();
}
else
{
showHint();
}
}
stop();

function sendLoadData():void
{
var dataRequest:URLRequest = new URLRequest(remotePath);
dataRequest.method = URLRequestMethod.POST;

// define the custom parameters that will be sent to the remote file
var params:URLVariables = new URLVariables();
params.rwPassword = rwPassword.text;

dataRequest.data = params;

var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, urlLoaderComplete);

try
{
urlLoader.load(dataRequest);
}
catch (event:Error)
{
showHint();
}
}

function urlLoaderComplete(event:Event):void
{
// once all the data has been sent and we'll check for a message sent
// from the remote file to tell us if the operation has ended with success or not
errorHandler(event.target.data.secure_response);
}

function errorHandler(message:Number):void
{
// check the message that was sent back from the remote file
//trace(message);
if (message == 1)
{
setSuccess();
}
else
{
setFailure();
}
}
}
}
}

Thanks for any help you could provide!

Comments

Changes to the checkProperties function

Hi Randy,

Try changing your checkProperties function to this:

private function checkProperties():void
{
if (properties.setBefore == false)
{
properties.textFieldText = textFieldDefaultText;
}
}

No luck

Hi Tristan! Thanks for helping! Jim Leichliter was hoping you might be able to help me out (I posted on the Adobe forums--he directed me to your framework) :)

I tried changing the checkProperties function as you suggested but no luck.

Even when I first open the properties dialog, the default text isn't being filled in. When I enter text manually into the field, it doesn't persist, either.

Do you have any other suggestions?

Thanks!

It's probably something on your stage

Your code looks fine to me. I'm guessing it must be something in the way the properties dialog frame is set up in Flash.

Is the rwURL text field nested into another MovieClip by any chance?

Not nested

That's good to know! The rwURL field isn't nested. I can send you the FLA file if you'd be so kind to take a look?