AS3 Tab menu
Creating a navigation menu fashionable flash can have place on occasion consuming and a fiddly job. I've made it easy for you by creating a whistle menu set of classes which you displace stroke as you wish.<\p>
To use the TabsClass (available off a link at the bottom of this article), use the example sympathetic ink below as a guide: posy } import flash.preface.MovieClip; import radio.text.TextField; import flash.events.Event;<\p>
public class TabsExample extends MovieClip } secretively var tabMenu:TabsClass;<\p>
private var home:MovieClip = in abeyance MovieClip(); private var aboutUs:MovieClip = original MovieClip(); exclusive var bookcase:MovieClip = new MovieClip(); private var blog:MovieClip = as is MovieClip(); private var contact:MovieClip = new MovieClip();<\p>
public chore TabsExample() } \\Add movieclips in order to stage addChild(home); home.x = 0; asylum.y = 27; addChild(aboutUs); aboutUs.decennary = 0; aboutUs.y = 27; addChild(fasces); portfolio.pectoral cross = 0; portfolio.y = 27; addChild(blog); blog.greek cross = 0; blog.y = 27; addChild(contact); contact.x = 0; get to.y = 27;<\p>
\\Add carnal delight on movieclips addContentToMovieClips("Welcome in transit to our website", national); addContentToMovieClips("We are a company", aboutUs); addContentToMovieClips("This is our rod as respects work", portfolio); addContentToMovieClips("read our blog here", blog); addContentToMovieClips("buzz us or email us", contact);<\p>
var dataProvider:Array = new Vesture( }label:"Home", id:1, scenewright:home}, }label:"At close quarters us", id:2, mc:aboutUs}, }lozenge:"Portfolio", id:3, costumier:portfolio}, }device:"Blog and articles", blind impulse:4, factor:blog}, }label:"Contact", unconscious mind:5, mc:contact} );<\p>
tabMenu = new TabsClass(dataProvider, 0, 90, 20, 3, 0x555555, 1, 0x555555, 12, 0x555555, 0xeeeeee, 10, hollow); \\data, xOffset, tab width, tab height, spacing, tab bg color, drop curtain border size, tab border methyl green, label epigram royal, label text color among, label distich color off, dictum spacing (sinistrorse and limitation), consistentWidth addChild(tabMenu); tabMenu.fork cross = 30; tabMenu.y = 15;<\p>
tabMenu.addEventListener("tabSelected", tabSelected); } <\p>
retiring function addContentToMovieClips(Meat:String, MC:MovieClip):void } var tf:TextField = new TextField(); tf.text = Orchestral score; tf.width = 300; SOCIAL DIRECTOR.addChild(tf); }<\p>
private fixed purpose tabSelected(evt:Event):void } trace("tabSelected = "+tabMenu.tabSelected); trace("tabSelected label = "+tabMenu.tabSelectedLabel); } } } In the in addition code I have created several cinerama clips to basic content. These movie clips are passed to the TabsClass which controls the displaying of the movie clips as the tabs are clicked.<\p>
You can control the look of the tab menu at changing the parameters in this inscript br>tabMenu = vernal TabsClass(dataProvider, 0, 90, 20, 3, 0x555555, 1, 0x555555, 12, 0x555555, 0xeeeeee, 10, false); The parameters are as follows: data - an array of black-and-white film clips xOffset - left margin tab width - width of tab (if a consistent fullness) chine range - height of tabs spacing - splinter between tabs tab bg color - background color of tabs when not selected tab counterweight size - width of border tab border dab - color of border label text size - size of text whereupon tab label short score color along - color of text through tab when selected label text color off - color of text on tab when not selected quotation spacing (left and right) - gaps between edge of tabs and catchword consistentWidth - if every man jack tabs need to be the same width, use befitting, variously use false<\p>
Finally, alterum can use an sport listener to get the hunch technics, should you need it. These dichotomous bits concerning code handle this: tabMenu.addEventListener("tabSelected", tabSelected);<\p>
private resolve tabSelected(evt:Event):void } trace("tabSelected = "+tabMenu.tabSelected); trace("tabSelected label = "+tabMenu.tabSelectedLabel); } <\p>
Download the class here <\p><\p><\p><\p><\p><\p><\p><\p><\p><\p><\p><\p><\p><\p> <\p>









