Quick help converting AS3 class to AS2?

I’m helping someone design their own radio button, so I spend 10 minutes or so getting more details and another 10 minutes writing the class and perfecting it.

When it is finally done, they reply, “Oh. That’s AS3. Is there an AS2 version?” :trout:

How different are AS2 classes from AS3? Would it take too long for someone to do a quick conversion or just point out the differences in this code?

package
{
    public class CustomRadioButton extends MovieClip
    {
   
        public function CustomRadioButton(text:String, value:*, category:String):void
        {
            this.text = text;
            this.value = value;
            
            _category = category;
            _id = CustomRadioButton.register(this);
            
            //It may come in handy to give a name to the radio button
            this.name = "rb_" + this.category + "_" + this.id;
        }
        
        /*  INSTRUCTIONS FOR USE
        *   Save this file as "CustomRadioButton.as"
        *   Create a new MovieClip, and name it CustomRadioButton. In the properties panel,
        *   set the class definition to this file. Create two frames on the MovieClip.
        *   Frame 1 should be how the Radio Button looks when it's not selected.
        *   Frame 2 should be how the Radio Button looks when it IS selected/checked.
        *   Also, place a new TextField onto the stage and name it "rb_text".
        *   That is all. :)
        */
        
        //PROPERTIES
                
        public var value:*;
        
        //The category cannot be changed as soon as it is set
        private var _category:String;
        public function get category():String
        {
            return _category;
        }
        
        public function get text():String
        {
            return rb_text.text;
        }
        public function set text(value:String):void
        {
            rb_text.text = value;
        }
        
        
        internal var _selected:Boolean = false;
        public function get selected():Boolean
        {
            return _selected;
        }
        public function set selected(value:Booelan):void
        {
            CustomRadioButton.setSelectionID(this.category, this.id);
        }
        
        
        //The category cannot be changed as soon as it is set
        private var _id:int;
        public function get id():String
        {
            return _id;
        }
        
        //The following code keeps track of all radio button instances
        //and deselects radio buttons when another one in the same 
        //category is selected
        
        private static var currentCategorySelection:Object = new Object();
        private static var allCategories:Object = new Object();
        
        
        internal static function setSelectionID(category:String, id:int)
        {
            currentCategorySelection[category] = id;
            
            var itemsInCategory:Array = allCategories[category];
            for (var i:int = 0; i < itemsInCategory; i++)
            {
                var item:CustomRadioButton = itemsInCategory*;
                if (item.id == id)
                {
                    item._selected = true;
                    item.gotoAndStop(2);
                }
                else
                {
                    item._selected = false;
                    item.gotoAndStop(1);
                }
            }
        }
        
        
        public static function getSelectionInCategory(category:String):CustomRadioButton
        {
            if (allCategories.hasOwnProperty(category))
            {
                var currentSelectionID:int = currentCategorySelection[category];
                return allCategories[category][currentSelectionID];
            }
            else
            {
                trace("Unknown category");
                return null;
            }
        }
        
        public static function getSelectionValueInCategory(category:String):*
        {
            var selection:CustomRadioButton = CustomRadioButton.getSelectionInCategory(category);
            if (selection == null)
            {
                return null;
            }
            else
            {
                return selection.value;
            }
        }
        
        private static function register(item:CustomRadioButton):int
        {
            var category:String = item.category;
            if (allCategories.hasOwnProperty(category))
            {
                //Just add it to the current list
                allCategories[category].push(item);
            }
            else
            {
                //Create this new category
                allCategories[category] = new Array();
                allCategories[category].push(item);
                
                //Set this new item to immediately selected
                currentCategorySelection[category] = 0;
                item._selected = true;
                item.gotoAndStop(2);
            }
            
            return (allCategories[category].length - 1);
        }

    }
}

Yes, I know it’s inefficient and ugly, but it’s made to be reader friendly. :bored:

I would really appreciate a hand if anyone is up for it.