Question

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?

Was it helpful?

Solution

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:

Enums in AS3 / Flash / Flex?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top