Click here to Skip to main content
15,881,204 members
Articles / Web Development / ASP.NET

Flash and Web Services

Rate me:
Please Sign up or sign in to vote.
4.58/5 (11 votes)
4 Jan 2006 71K   748   43   13
An easy way to working with Flash and Web Services.

Image 1

Introduction

This sample will log you in with a Web Service, serialize the data from a database, and use the serialization class in Flash.

Background

You can get data from a server application in several ways, but I discovered that when working with .NET, using a serialization class is very easy.

Using the code

We will use the a Web Service and a serilazation class and a function in Flash to get the user information. Here is the login method in the Web Service:

C#
[WebMethod]
public oUsers loginUser(string sUsername, string sPassword)
{
    oUsers objUsers = new oUsers();
    try
    {
        if( sUsername.Equals("admin") && 
            sPassword.Equals("admin") )
        {
            objUsers.sEmail = "admin@administrator.com";
            objUsers.sName = "Adam";
            objUsers.sPassword = "admin";
            objUsers.sUsername = "admin";
        }
        else
        {
            throw new ApplicationException("Wrong user!");
        }
    }
    catch
    {
        throw new ApplicationException("Error");
    }
    return objUsers;
}

Here is the serialization class:

C#
[Serializable]
public class oUsers
{
    public string sName;
    public string sEmail;
    public string sUsername;
    public string sPassword;

    public oUsers()
    {
    }
}

Here is the Flash script for the root:

C#
//stop the secvens of the time line
stop();

//importing the webservice classes
import mx.services.*;

//declareing the an global variable for easy access
_global.webServicen = 
  new WebService("http://localhost/WebServiceAndFlash/login.asmx?WSDL");

//cleaning up the textboxes

mcLogin.txtUsername.text = "admin";
mcLogin.txtPassword.text = "admin";
mcLogin.txtName.text = "";
mcLogin.txtEmail.text = "";
mcLogin.txtUser.text = "";
mcLogin.txtPass.text = "";

Given below is the script for the OnClick function:

JavaScript
on(release){
    var objServicen = _global.webServicen.loginUser(
        _root.mcLogin.txtUsername, _root.mcLogin.txtPassword);
    objServicen.onResult = function(result)
    {
        trace("login");
        //declare the Userobject

        var oUser = new objServicen.oUsers();
        oUser = result;
        
        _root.mcLogin.txtName = "SDF" + oUser.sName;
        _root.mcLogin.txtEmail = oUser.sEmail;
        _root.mcLogin.txtUser = oUser.sUsername;
        _root.mcLogin.txtPass = oUser.sPassword;
        
    }
    
    objServicen.onFault = function(fault)
    {
        _root.mcAlert._x = "-0.3";
        _root.mcAlert._y = "-0.7";
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Värderingsdata
Sweden Sweden
Systemdeveloper at Värderingsdata in Sweden

Comments and Discussions

 
General2010 and yoour code helped me Pin
ZED023-Jun-10 3:19
ZED023-Jun-10 3:19 
Generalcommunication problem on http environnement Pin
quineman25-Mar-08 1:46
quineman25-Mar-08 1:46 
QuestionHow to pass a custom object to the WebService ? Pin
Yasin7523-May-07 23:15
Yasin7523-May-07 23:15 
QuestionFault Handler with Error Information? Pin
gollum915-Feb-07 3:13
gollum915-Feb-07 3:13 
QuestionSequrity (global sequrity configuration) Pin
sympthom 99-Feb-07 2:53
sympthom 99-Feb-07 2:53 
GeneralCan't open the csproj in VS2003 Pin
LotharLanger5-Jan-06 3:05
LotharLanger5-Jan-06 3:05 
GeneralRe: Can't open the csproj in VS2003 Pin
daniel_nilsson5-Jan-06 7:42
daniel_nilsson5-Jan-06 7:42 
GeneralRe: Can't open the csproj in VS2003 Pin
LotharLanger5-Jan-06 9:34
LotharLanger5-Jan-06 9:34 
GeneralRe: Can't open the csproj in VS2003 Pin
daniel_nilsson7-Jan-06 23:11
daniel_nilsson7-Jan-06 23:11 
QuestionDoes anyone have pointers to further reading? Pin
Mindphaser4-Jan-06 11:08
Mindphaser4-Jan-06 11:08 
AnswerRe: Does anyone have pointers to further reading? Pin
daniel_nilsson4-Jan-06 21:31
daniel_nilsson4-Jan-06 21:31 
What are you intrested in Flash or the server technics??

Here is some links and books
http://www.flash-remoting.com/
http://www.macromedia.com/devnet/flash/webservices.html
http://www.oreillynet.com/pub/a/javascript/2003/01/09/flash.html

//Daniel Nilsson

-- modified at 3:34 Thursday 5th January, 2006
GeneralRe: Does anyone have pointers to further reading? Pin
Mindphaser4-Jan-06 22:36
Mindphaser4-Jan-06 22:36 
GeneralRe: Does anyone have pointers to further reading? Pin
daniel_nilsson7-Jan-06 23:12
daniel_nilsson7-Jan-06 23:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.