How to pass variables from asp.net coad to swf file?

Dear all, I trying to creat login form in flash 8, can you please tell

Page 1 of 1

1 Replies - 5832 Views - Last Post: 23 December 2008 - 09:06 AM Rate Topic: -----

#1 ani30oct   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 23-December 08

How to pass variables from asp.net coad to swf file?

Posted 23 December 2008 - 08:54 AM

I m using the following example login form of flash8 sample........thanks




//****************************************************************************
//Copyright  2005 Macromedia, Inc. All Rights Reserved.
//The following is Sample Code and is subject to all restrictions on
//such code as contained in the End User License Agreement accompanying
//this product.
//****************************************************************************

/*
Creating a Form Example
This example shows you how to create a form that captures and validates data, 
which is sent to the server. The SWF file also handles a response from the server.
Correct login is: u: Herbert, p: glasses
*/

/* Import the required classes. 
   Use the wildcard (*) to import all classes within the mx.controls package. 
   This includes the TextInput, Button and Label. */
import mx.controls.*;

// strict type instances on the Stage.
var status_lbl:Label;
var username_ti:TextInput;
var password_ti:TextInput;

password_ti.password = true;

/* Define a click handler for the submit_btn Button instance, 
   which calls the checkForm function (defined below). */
submit_btn.clickHandler = function() {
	checkForm();
};

/* Create a listener object which is used with both the 
   username_ti and password_ti TextInput instances. 
   This listener "listens" for the "enter" event, 
   which triggers when the enter key is pressed. */
var formListener:Object = new Object();
formListener.enter = function(evt) {
	checkForm();
};
username_ti.addEventListener("enter", formListener);
password_ti.addEventListener("enter", formListener);

// set the form focus to the username_ti TextInput instance.
Selection.setFocus(username_ti);

/* define the checkForm function, which is responsible for checking that the 
   required fields are filled in and using LoadVars to send login information to the server to validate. */
function checkForm() {
	// ensure that the username_ti field isn't blank.
	if (username_ti.text.length == 0) {
		// if the username_ti field is empty, display an error message in the status_lbl Label instance.
		status_lbl.text = "<font color=\"#EFDFDC\">Please enter user name.</font>";
		// set the form focus to the username_ti TextInput instance.
		Selection.setFocus(username_ti);
		// exit the checkForm function.
		return false;
	}
	/* if the password_ti TextInput instance is blank, 
	   display an error message in the status_lbl Label instance and exit the checkForm function. */
	if (password_ti.text.length == 0) {
		status_lbl.text = "<font color=\"#EFDFDC\">Please enter password.</font>";
		Selection.setFocus(password_ti);
		return false;
	}
	// clear the status_lbl Label instance
	status_lbl.text = "";
	/* define two instances of the LoadVars object. 
	   One is used to hold the variables being sent to the server-side script,
	   and the other one is used to hold the variables returned by the 
	   LoadVars.sendAndLoad method. */
	var result_lv:LoadVars = new LoadVars();
	var login_lv:LoadVars = new LoadVars();
	// copy the value of the two TextInput components into the login_lv LoadVars instance.
	login_lv.username = username_ti.text;
	login_lv.password = password_ti.text;
	/* send the variables in the login_lv instance to the server-side script 
	   using the POST method (send as Form variables rather than along the URL)
	   and place the results returned in the result_lv instance. */
	login_lv.sendAndLoad("http://www.flash-mx.com/mm/login.cfm", result_lv, "POST");
	// When the results are received from the server...
	result_lv.onload = function(success:Boolean) {
		// If Flash is able to successfully send and load the variables from the server-side script...
		if (success) {
			// if the server returned the value of isValidLogin with a value of 1...
			if (this.isValidLogin == 1) {
				/* set the status_lbl Labal to a "success" message. 
				   Typically here you'd do a gotoAndPlay or set any local variables 
				   related to a successful login. */
				status_lbl.text = "<font color=\"#009900\"><b>login successful.</b></font>";
				/* else the login information wasn't valid, 
				   therefore display an error message in the status_lbl Label instance. */
			} else {
				status_lbl.text = "<font color=\"#EFDFDC\">invalid user name / password.</font>";
				// set the form focus to the username_ti TextInput instance and select the existing text.
				Selection.setFocus(username_ti);
				Selection.setSelection(0, username_ti.text.length);
			}
			/* this code is only executed if for some reason the SWF is
			   unable to connect to the remote page defined in LoadVars.sendAndLoad */
		} else {
			status_lbl.text = "<b>Unable to connect to login URL</b>";
			username_ti.enabled = false;
			password_ti.enabled = false;
			submit_btn.enabled = false;
		}
	};
	return true;
}


Is This A Good Question/Topic? 0
  • +

Replies To: How to pass variables from asp.net coad to swf file?

#2 marcells23   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 143
  • Joined: 22-August 07

Re: How to pass variables from asp.net coad to swf file?

Posted 23 December 2008 - 09:06 AM

If you have the experience is ASP.NET you may want to look into Web Services. Flash could then consume this web service and the login would be dealt with on the ASP.NET side and the result would be returned back to your flash via XML.
Flash -Web Service Example
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1