Go Back   SitePoint Forums > Forum Index > Design Your Site > Flash and Actionscript
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 6, 2009, 14:58   #1
luke_4_mls
SitePoint Member
 
Join Date: Apr 2009
Posts: 10
AS3 dynamic call to MC - need help with Target Path

I'm working on the basics of building a Flash website. For navigation, I have several buttons in a MC (nav) that when clicked make the proper page visible and hide the current page. I've used clever naming to access the page MC's dynamically. Here's my code:

Actionscript Code:
a1PAGE.visible = true;
b1PAGE.visible = false;
c1PAGE.visible = false;
d1PAGE.visible = false;
var current:MovieClip = a1PAGE;
 
nav.a1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.b1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.c1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.d1.addEventListener(MouseEvent.CLICK, BTNCLICK);
 
function BTNCLICK(event:MouseEvent):void {
    current.visible = false;
    var caller:String = event.target.name + "PAGE";
    var called:MovieClip = this[caller];
    called.visible = true;
    current = called
}

It works fine. But I need to store all the pages into an MC. So here's that code:
Actionscript Code:
pages.a1PAGE.visible = true;
pages.b1PAGE.visible = false;
pages.c1PAGE.visible = false;
pages.d1PAGE.visible = false;
var current:MovieClip = pages.a1PAGE;
 
nav.a1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.b1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.c1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.d1.addEventListener(MouseEvent.CLICK, BTNCLICK);
 
function BTNCLICK(event:MouseEvent):void {
    current.visible = false;
    var caller:String = event.target.name + "PAGE";
    var called:MovieClip = this[caller];
    pages.called.visible = true;
    current = pages.called
}

Except Flash doesn't like my last 2 lines of code. (Error #1010: A term is undefined and has no properties.) So how do I reference the page instance name dynamically and add a target path to it that flash will accept? It must retain this structure:

Scene 1
|--AS located here
|--nav
| |--nav buttons
|--pages
| |--pages mc's

thanks for the help
luke_4_mls is offline   Reply With Quote
Old Nov 6, 2009, 16:02   #2
luke_4_mls
SitePoint Member
 
Join Date: Apr 2009
Posts: 10
I figure it:

Actionscript Code:
pages.a1PAGE.visible = true;
pages.b1PAGE.visible = false;
pages.c1PAGE.visible = false;
pages.d1PAGE.visible = false;
var current:MovieClip = pages.a1PAGE;
 
nav.a1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.b1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.c1.addEventListener(MouseEvent.CLICK, BTNCLICK);
nav.d1.addEventListener(MouseEvent.CLICK, BTNCLICK);
 
function BTNCLICK(event:MouseEvent):void {
    current.visible = false;
    var caller:String = event.target.name + "PAGE";
    var called:MovieClip = this.pages[caller];
    called.visible = true;
    current = called;
}
luke_4_mls is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 03:36.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved