Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4119376
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:04:57+00:00 2026-05-20T23:04:57+00:00

I created some button states in flash (swc), and I want to use them

  • 0

I created some button states in flash (swc), and I want to use them in a pure AS3 project. They are movie clips with class of neatButton_on and neatButton_off respectively. I call them like this:

public class neatButton extends neatModule
    {
        private var stateOn:neatButton_on;
        private var stateOff:neatButton_off;
        private var modContainer:Sprite = new Sprite();

        public function neatButton() 
        {
            addChild(modContainer);
            modContainer.x = 200;
            modContainer.y = 200;
            stateOff = new neatButton_off();
            stateOn = new neatButton_on();
            modContainer.addChild(stateOn);
            modContainer.addChild(stateOff);

            modContainer.addEventListener(MouseEvent.MOUSE_OVER, hover);
            modContainer.addEventListener(MouseEvent.MOUSE_OUT, unhover);
        }

        private function hover(e:MouseEvent):void
    {
        stateOff.visible = false;
    }

    private function unhover(e:MouseEvent):void
    {
        stateOff.visible = true;
    }
    }

My question is, is this the best way to do this? I’ve also used assets, especially for different states of the same item, where I’ve put everything in one movie clip and then switched frames as needed. Is one way faster than the other? is there a best practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:04:58+00:00Added an answer on May 20, 2026 at 11:04 pm

    I’ll share a simple class I use for creating two state image buttons. I use Tweenlite to effect a alpha tween on rollover.

        package com.b99.display.composite
        {
            import flash.display.*;
            import flash.events.MouseEvent;
    
            import com.greensock.*;
    
            /**
             * ...
             * @author Bosworth99
             */
            public class ImgButton extends Sprite
            {
                private var _canvas         :Sprite = new Sprite();
                private var _up             :Sprite;
                private var _over           :Sprite;
                private var _hit            :Shape;
    
                private var _intent         :String;
    
                public function ImgButton(intent:String) 
                {
                    _intent = intent;
    
                    super();
                    init();     
                }
    
                private function init():void
                {
                    constructButton();
                    addEventHandlers();
                }
    
                private function constructButton():void
                {
    
                    this.addChild(_canvas);
    
                    switch (_intent) 
                    {
                        case "button1":
                        {
                            _up     = new yourUpClip1()
                            _over   = new yourOverClip1();
                            break;
                        }
                        case "button2":
                        {
                            _up     = new yourUpClip2()
                            _over   = new yourOverClip2();
                            break;
                        }
                        case "button3":
                        {
                            _up     = new yourUpClip3()
                            _over   = new yourOverClip3();
                            break;
                        }
                    }
    
                    _canvas.addChild(_up);
    
                    with (_over) 
                    {
                        alpha   = 0;
                    }
                    _canvas.addChild(_over);
    
                    _hit = new Shape();
                    with (_hit) 
                    {
                        graphics.beginFill(0x00FF40, 0);
                        graphics.drawRect(0, 0, _up.width + 5, _up.height +5);
                        graphics.endFill();
                        x       = -5;
                        y       = -5;
                    }
                    _canvas.addChild(_hit)
    
                    _up.cacheAsBitmap       = true;
                    _over.cacheAsBitmap     = true;
                    _hit.cacheAsBitmap      = true;
    
                    this.buttonMode         = true;
                    this.mouseEnabled       = true;
    
                }
    
                private function addEventHandlers():void
                {
                    _hit.addEventListener(MouseEvent.MOUSE_OVER,    over, false, 0, true);
                    _hit.addEventListener(MouseEvent.MOUSE_OUT,     out, false, 0, true);
                }
    
                private function over(e:MouseEvent):void 
                {
                    TweenLite.to(_over, .2,     {alpha:1   } );
                }
                private function out(e:MouseEvent):void 
                {
                    TweenLite.to(_over, .2,     {alpha:0   } );
                }
    
                public function destroy():void
                {
                    _hit.removeEventListener(MouseEvent.MOUSE_OVER, over);
                    _hit.removeEventListener(MouseEvent.MOUSE_OUT,  out);
    
                    _canvas.removeChild(_up);
                    _up = null;         
    
                    _canvas.removeChild(_over);
                    _over = null;       
    
                    _canvas.removeChild(_hit);
                    _hit = null;
    
                    this.removeChild(_canvas)
                    _canvas = null;
    
                    this.parent.removeChild(this);
                }
        //+++++++++++++++++++++++++++++++  end ++++++++++++++++++++++++++++++++++++++++
            }
    
        }
    

    You just need to send in a string that gets fed into a switch statement. This class can be used for multiples cases this way. And then to kill, simply call _imgButton.destroy() in the parent.

    This class is essentially similar to yours, just with some added functionality 😉

    cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a NIB file with some button controls on it, and as a
i created some buttons in an xml layout. They get their names from string
I've got some dynamic created buttons in my GridView (adding them OnDataBound), but when
I am creating some action script to simulate 3 button states and load in
I am trying to create a rich text editor. I have created some buttons
I create some dynamic textbox's and a button in a placeholder and would like
I created some widgets with jQuery UI and I notice that buttons have a
I created a simple tooltip for some buttons in an admin panel I am
I have some code that dynamically creates a new button through JavaScript that when
I am trying to create a Help button for my installer, bur for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.