O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

20.19. Returning Typed Objects from ASP.NET

Problem

You want to return a typed object to Flash from a .NET back end.

Solution

Use an ASObject and set the ASType property to match the name of the ActionScript class as it is registered in Flash.

Discussion

Flash automatically attempts to convert any returned ASObject values into ActionScript datatypes. It tries to find an ActionScript class that is registered within Flash with the same name as the value of the ASObject’s ASType property. Therefore, you can return a typed object to a Flash movie from a .NET back end by using an ASObject and setting its ASType property to the name of an ActionScript class as it is registered in the Flash movie. Use the Add( ) method to add properties to the ASObject. Here is an example of a .NET DLL method that returns an ASObject:

public FlashGateway.IO.ASObject getTypedObject(  ) {

  // Create an ASObject.
  FlashGateway.IO.ASObject aso = new FlashGateway.IO.ASObject(  );

  // Add properties to the object.
  aso.Add("a", "eh");
  aso.Add("b", "bee");

  // Set the ASType of the ASObject to match the name 
  // of a registered ActionScript class.
  aso.ASType = "MyClass";

  // Return the ASObject.
  return aso;
}

Here is an example snippet of ActionScript code that handles the ASObject that the preceding code returns:

function MyClass(a, b) {
  this.a = a;
  this.b = b;
}
MyClass.prototype.a;
MyClass.prototype.b;

// Add a method that just writes all the properties to the Output window.
// This example simply illustrates that the 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required