Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to make a menu from "movieclip buttons"classes as3 flash

New Here ,
Feb 11, 2013 Feb 11, 2013

Hi,

I've been trying to make an array of buttons so I can place them on the stage as a menu, i am using different images so i have loaded them into a single movieclip and want to each frame from that movieclip and put them in an array.

Am i doing this wrong?

I am trying to use AS3 and classes to call this as its part of a larger application

Any help would be great

TOPICS
ActionScript
523
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 11, 2013 Feb 11, 2013

It is hard to tell if you are doing anything wrong because it is difficult to understand what you are doing from your explanation.  You do not indicate you have a problem.

If you have tried something and it is not working, explain the details of it and show the code that is being used that is relevant to what is not working.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 11, 2013 Feb 11, 2013
LATEST

Thanks Ned.

Here is the code I am using:

package classes {

 

          import flash.display.MovieClip;

          import com.greensock.*;//for Tweening ability

          import com.greensock.TweenLite;

          import com.greensock.easing.*;

          import flash.filters.BlurFilter;

          import flash.events.Event;

          import flash.utils.Timer;

          import flash.events.TimerEvent;

          import flash.display.*;

          import flash.events.*;

          import flash.sampler.StackFrame;

 

          public class menuScreen extends MovieClip

          {

 

                    // Declares all the variables of the file

                    private var numOfmenuItems:uint = 5;// number of menu Items to put on stage

 

                    // This declares the containerMC where all files will be fed into

                    private var containerMc:ContainerMc = new ContainerMc();

 

                    private var angl:Number;

 

                    private var itemMc:ItemMc = new ItemMc();

                    private var itemArray:Array = new Array();

 

                    private var radiusX:uint = 400;// width of menu

                    private var radiusY:uint = 70;// height of menu

                    private var centerX:Number = 0;// x position of center of menu

                    private var centerY:Number = 225;// y position of center of menu

 

 

                    public function menuScreen()

                    {

                              trace ("container")

                              // constructor code

                              //Add content container;

                              containerMc.y = stage.stageHeight / 2;

                              containerMc.x = stage.stageWidth / 2;

                              addChild(containerMc);

                              containerMc.addChild(ItemMc)

                    }

                              // place Menu Items on stage

                    public function initMenuItems(numOfmenuItems:Number):void

                    {

                              trace ("MenuItems")

                              for (var i:uint = 0; i < numOfmenuItems; i++)

                              {

                                        var arrayBoxItem:String = ("module" + (i+1) + "_");

 

                                                  // Item class extends ItemInner in FLA library.

                                                  itemMc.angl = i * ((Math.PI * 2) / numOfmenuItems);

                                                  itemMc.alpha = 0.8;

                                                  itemMc.name = (arrayBoxItem);

                                                  trace(itemMc.name);

                                                  containerMc.addChild(itemMc);

                                                  itemArray.push(itemMc);

 

                                                  itemMc.itemHitter.buttonMode = true;

                                                  itemMc.addEventListener(Event.ENTER_FRAME, enterFrameHandler);

                                                  // listen for MouseEvents only on icons, not on reflections;

                                                  itemMc.itemHitter.addEventListener(MouseEvent.CLICK, clickHandler);

                                                  itemMc.itemHitter.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);

                                                  itemMc.itemHitter.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);

                                                  itemMc.iconMc.gotoAndStop(arrayBoxItem);

                              }

                    }

 

                    public function clickHandler(event:MouseEvent):void

                    {

                              // clean up your listeners before you do anything else to free up

                              // user's CPU resources

                                        var itemMc:ItemMc = itemArray;

                                        for (var i:uint = 0; i < itemArray.length; i++)

                                        {

 

                                        itemMc.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);

                                        itemMc.itemHitter.removeEventListener(MouseEvent.CLICK, clickHandler);

                                        itemMc.itemHitter.removeEventListener(MouseEvent.ROLL_OVER, rollOverHandler);

                                        itemMc.itemHitter.removeEventListener(MouseEvent.ROLL_OUT, rollOutHandler);

                                        // optional:;

                                        TweenLite.to(itemMc, 1, {scaleX:0, scaleY:0, alpha:0.1, ease:Elastic.easeInOut});

                                        TweenMax.to(itemMc, 1, {blurFilter:{blurX:5, blurY:5}});

                                        // to replace the carousel again see reInit() function

                                        // FIGURE OUT A WAY TO REMOVE ITEMS

                                        //this.removeChild(itemMc);

                                        }

 

                    }

 

                    public function enterFrameHandler(event:Event):void

                    {

                              event.target.x = Math.cos(event.target.angl) * radiusX + centerX;// x position of Item

                              event.target.y = Math.sin(event.target.angl) * radiusY + centerY;// y postion of Item

                              // scale Item according to y position to give perspective

                              var s:Number = event.target.y / (centerY + radiusY);

                              event.target.scaleX = event.target.scaleY = s;

                    }

 

                    ////////////////////////////////////////////////////////////////////////////////////////////////////// ITEMS WHEN ROLLOVER & OUT

                    public function rollOverHandler(event:MouseEvent):void

                    {

                              var currentModel:String = event.target.parent.iconMc.parent.name;

                              event.target.parent.alpha = 1;

                              TweenLite.to(event.target.parent.iconMc.tooltipMc, 1, {alpha:1, y:-40, ease:Elastic.easeOut});

                              event.target.parent.iconMc.tooltipMc.tipHeader.gotoAndStop(currentModel);

                    }

                    function rollOutHandler(event:MouseEvent):void

                    {

                              event.target.parent.alpha = 0.8;

                              TweenLite.to(event.target.parent.iconMc.tooltipMc, .5, {alpha:0, y:-27});

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines