View Full Version : Tab-aruskie
Persistent1
October 22nd, 2009, 01:21 PM
Hi there. I need to prototype a tabbed interface in Flash, AS3. I was thinking of 3 MC buttons on my timeline (let's say there instance names are; tab1, tab2, tab3).
In theory I would have a respective MC (instance names; content1, content2, content3) for each tab and when the tab was clicked on, it's MC would appear below (i.e. tab1 was clicked and in result shows content1).
Any guidance as to how I would structure this in Flash–I'm blanking on the code structure to get this working and can't use easy goto's on frame ids as once performed in AS2 :-\
Thanks for the guidance. :)
micken
October 22nd, 2009, 01:56 PM
What would probably be easiest is to use a Dictionary data structure. This way you can link each of your tabs directly to it's associated MovieClip.
Think of it like using your tab MCs as array indexes for your content MCs. I would then add an event listener to each tab for mouse clicks and swap the associated content movieclips whenever the user click so the tab they clicked on comes to the front.
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.utils.Dictionary;
public class TabbedContents extends MovieClip
{
private var mCurrentTab:MovieClip = null;
private var mTabs:Dictionary = null;
public function TabbedContents()
{
mTabs = new Dictionary();
content1 = new MovieClip();
content2 = new MovieClip();
content3 = new MovieClip();
tab1 = new MovieClip();
tab2 = new MovieClip();
tab3 = new MovieClip();
mTabs[tab1] = content1;
mTabs[tab2] = content2;
mTabs[tab3] = content3;
addChild(tab1);
addChild(tab2);
addChild(tab3);
addChild(content1);
addChild(content2);
addChild(content3);
mCurrentTab = tab1;
tab1.addEventListener(MouseEvent.CLICK, onTabClick);
tab2.addEventListener(MouseEvent.CLICK, onTabClick);
tab3.addEventListener(MouseEvent.CLICK, onTabClick);
}
public function onTabClick(e:Event):void
{
swapChildren(mTabs[mCurrentTab], mTabs[e.target]);
mCurrentTab = e.target;
}
}
}
I haven't actually tried to run that code but it should give a general idea of what I'm suggesting.
Persistent1
October 22nd, 2009, 02:38 PM
thx micken. I appreciate your guidance. so with your concept, would I create 3 MCs of content and set linkage identifiers as content1, content2, content3 ?
If so, I have already tried this and i'm getting this error when I test to publish:
1037: Packages cannot be nested.
micken
October 22nd, 2009, 03:08 PM
That depends on how your contents are set up. Are they on the stage already or are they in your library only? If you don't really need to change anything other than their z-order you can just put them on the stage of your main timeline and access them from your document class.
I'm not sure how you managed to get that error by linking..
Persistent1
October 23rd, 2009, 09:58 AM
i got that error by having the content mcs in the library only (not on the timeline) I'll try putting them on the timeline and see if I can get that to work out.
Thx.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.