views:

457

answers:

1

Sorry if the title is unclear - not sure how to phrase it. Feel free to edit it.

I have a web service written in C# and it uses an enum. When I am consuming this webservice with Flash, I had Flex generate the proxy classes - which also generates said enum in Actionscript. My problem is that I don't know how to use this generated Actionscript.

C# enum:

public enum ImageType
{
    None = 0,
    Png = 1,
    Jpg = 2,
    Gif = 3
}

Actionscript generated proxy class (cant change this):

public class ImageType
{
    public function ImageType() {}
    [Inspectable(category="Generated values", eumeration="None,Png,Jpg,Gif", type="String")]
    public var _ImageType:String;public function toString():String
    {
        return _ImageType.toString();
    }
}

Actionscript usage example (ie. this is how it should work in my brain):

var imgType:ImageType = ImageType.Png; //this does not actually work though

NOTE: Code is example only, but the structure is the same.

How would I go about using this ImageType enum in Actionscript?

A: 

AS3 does not support enumerations. I'm not immediately sure what the point of this generated proxy class is, but it isn't going to provide much of the enum behavior you're used to.

You'd have to do the following:

var imgType:ImageType = new ImageType();
imgType._imageType = "Png";

I know you said you cannot change the generated class, but if you wanted to create your own enumeration class, check the following question for links to official documentation as well as a helpful blog post on a custom enum implementation:

http://stackoverflow.com/questions/329652/enums-in-as3-flash-flex

Stiggler
cheers for your input mate. I was afraid that that was going to be the case. I'll give it another day or so to see if there are any other contributions but
Darko Z