~ocean Posted January 1, 2011 Share Posted January 1, 2011 I decided to give AS3 a go recently (I use to always work in AS2), and I made a button thing like this: ActionScript Code: import gs.TweenLite; import fl.motion.easing.*; var tabContainer:Sprite = new Sprite(); var tabArray:Array = new Array(); var txtArray:Array = ["Home", "About Me", "Gallery", "contact", "info", "Portfolio"]; var urlArray:Array = ["link01", "link02", "link03", "link04", "link05", "link06"]; var descArray:Array = ["Matthew Zheng", "Matthew Zheng", "Matthew Zheng", "Matthew Zheng", "Matthew Zheng", "Matthew Zheng"]; var tabcount:int = 6; // How much space between buttons var tabspacing:int = 10; var baseColor:uint = 0x000000; // Color for Mouse-Over var overColor:uint = 0x00CCFF; // Color for active button var activeColor:uint = 0xFF3300; var desctxt:Desctxt = new Desctxt(); desctxt.x = stage.stageWidth - (desctxt.width + tabspacing); desctxt.y = 75; desctxt.alpha = 0; addChild (desctxt); function initTab ():void { for (var i = 0; i < tabcount; i++) { var tab:Tab = new Tab(); TweenLite.to (tab.body, 0, {tint: baseColor}); tabArray.push (tab); tabArray.linkId = i; // Tabs x - Position tab.x = tabspacing * .5 + (stage.stageWidth - tabcount * (tab.width + tabspacing)) * .5 + Math.floor( i / 1 ) * (tab.width + tabspacing); // Tabs initial y - Position tab.y = 30; tab.txt.text = txtArray; tab.addEventListener (MouseEvent.MOUSE_OUT, tabOut); tab.addEventListener (MouseEvent.MOUSE_OVER, tabOver); tab.buttonMode = true; tab.mouseChildren = false; tabContainer.addChild (tab); } addChild (tabContainer); } function tabOver (event:MouseEvent):void { var target:Object = event.currentTarget; target.addEventListener (MouseEvent.MOUSE_UP, tabUp); if (target.activa != 1) { TweenLite.to (target.body, .2, {tint: overColor}); TweenLite.to (target, .8, {y: 70, ease: Elastic.easeOut}); } desctxt.desc.text = descArray[target.linkId]; TweenLite.to (desctxt, .8, {alpha:1}); } function tabOut (event:MouseEvent):void { var target:Object = event.currentTarget; target.removeEventListener (MouseEvent.MOUSE_UP, tabUp); TweenLite.to (target.body, 1.5, {tint: baseColor}); TweenLite.to (target, 1, {y: 30, ease: Back.easeInOut}); TweenLite.to (desctxt, 1, {alpha:0}); } function tabUp (event:MouseEvent):void { var target:Object = event.currentTarget; for (var i in tabArray) { if (tabArray != target) { tabArray.activa = 0; tabArray.addEventListener (MouseEvent.MOUSE_OVER, tabOver); tabArray.addEventListener (MouseEvent.MOUSE_OUT, tabOut); TweenLite.to (tabArray.body, 1.5, {tint: baseColor}); TweenLite.to (tabArray, 1, {y: 30, ease: Back.easeInOut}); } else { tabArray.activa = 1; tabArray.removeEventListener (MouseEvent.MOUSE_OUT, tabOut); TweenLite.to (tabArray.body, .3, {tint: activeColor}); Now from the back of my head AS2 for button coding would be like ActionScript Code: on(press){ gotoAndPlay("Home"); } Now I want that in my AS3 code so I can go to say, a frame with the instance name of Home. How can I do this without the use of URL's? Link to comment Share on other sites More sharing options...
Carl Posted January 2, 2011 Share Posted January 2, 2011 since each tab already has a linkId you could create a frameArray like: var frameArray:Array = new Array("home", "about", "contact", "etc"); the tabUp() function for MOUSE_UP could include something like var target:Object = event.currentTarget; trace("my linkId " + target.linkId); trace("my frame " + urlArray[target.linkId]); gotoAndPlay(urlArray[target.linkId]); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now