Skip to main content
Participant
November 19, 2009
Question

Interactive server and WebService

  • November 19, 2009
  • 1 reply
  • 259 views

Below I have added code example to illustrate my problem.

I am using Interactive flash server 3.5 and developing client using Flex builder 3.

First off I am new to flash, actionscript, java script, ..., and I need server side to interact with a database. I have developed the below code that through trace statements seems to work, but when I try to access variable(s) they are still in their initial state.  The trace statements in "Results.onResult = function(result)" are called and printed out to the Administration console. In main.asc there is an interval that checks the variable(s) and prints trace statement. app.MyDataManager.initCalled is always false. I'm not sure if this is the right terminology, but the call back from the web service seems to be in different memory or scope.

What am I missing here. I know the function setInterval(...) you have to pass this. But I have been unable to find an equivalent for WebService. Is it possible to do what I'm trying to do?

Any help or suggestions would be greatly appreciated.

//######################################################

// DataManager.asc

//---------------------------------------------------------------------------------------------

function DataManager ()
{
  this.status = 0;
  this.initCalled = false;
}


DataManager.prototype.UpdateVars = function (Id)
{
  MyService = new WebService "http://david/myservice/Service1.asmx?wsdl");

  Results = MyService.GetData(Id);
  Results.onResult = function(result)
  {
     trace (result);

     var myXML = new XML (result);
     this.status = myXML.firstChild.childNodes[0].attributes.Status;
     this.initCalled = true;
     …
     trace ("Status: " + this.status); }
     …
  }

}

//---------------------------------------------------------------------------------------------

//main.asc

//---------------------------------------------------------------------------------------------

load ("DataManager.asc")

application.onAppStart = function()
{
   trace("onAppStart");

   this.MyDataManager = new DataManager ();
   this.timer_int = setInterval(CheckForEvent, 1000, this);
   this.timerCounter = 0;
}

application.onConnect = function(client, name, identifier, ID)
{
   this.MyDataManager.Init(ID);
   application.acceptConnection(client);
}

function CheckForEvent (app)
{
  if(app.MyDataManager != null) && (app.MyDataManager.initCalled == true) )
  {
    trace ("Status: “ + app.MyDataManager.status);
  }
  else
  {
     if(app.MyDataManager == null)
     {
        trace ("if(app.MyDataManager == null)");
     }
     else if(app.MyDataManager.initCalled == false)
     {
        trace ("app.MyDataManager.initCalled == false");
     }
     else
     {
        trace ("CheckForEvent UNKNOWN condition!!");
     }
   }
}
//######################################################

    This topic has been closed for replies.

    1 reply

    BcisR_DAuthor
    Participant
    November 19, 2009

    Ultimately I need to access a database from the server side. Whether it is done using a

    web service or another means. What I am saying is, I don't have to use a WebService class. The example given is my first attempt. If anyone has another approach or suggestion I could use, that would be great.

    Is interacting with a database on the server side common?