Mailing List
Home
Forum Home
Flash Pro
Subjects
Firework Effect
setInterval bug identified and fixed
setInterval bug identified and fixed
ScrollPane component doesn 't auto update
Help: MX 2004 How to script a print button to print the entire sli
Event Dispatcher between classes
memory management removeMovieClip /
MX2004 Dataset itemClassName
Order of events per frame
XML to Object help
Textfield prototype question
Flash and QuickTime VR
Reading and displaying RSS feeds in Flash MX
Flash MX 2004 Sucks
AW: [Flashcoders] Switch/Case vs If/else
AW: [Flashcoders] Switch/Case vs If/else
Flash Interface with 10mb xml file
Web Service Results
Listener Object 's best practice
 
Re: Writing a function for navigating a site: re-use and re-st

Re: Writing a function for navigating a site: re-use and re-st

2004-04-16       - By marisa_antonaya

 Back
Hmmm, I tried replying to this yesterday, but the post didn't go through, so
here goes
again.

Thanks for the valuable advice, I think I see where I went wrong, and also that
I may
be headed towards an inflexible design for this site. I have it set up in
scenes, but
because there are common elements to all the pages (navigation, logo, icons), I
was
worried about the file size, which is why I was hoping to cut down on the
amount of
script through a function that could be called from each scene.

But now I'm wondering if I shouldn't rethink the structure, since I see the
potential
problems with scenes. Right now, the site is small (one-level clicking), but it
will grow
and I'll need to add pages. In this case, should I create a navigation swf, and
load the
other pages (the content) into this main movie? Or should I work within a
single scene
and make a layer for each separate page, having them appear on the timeline as
needed?

Thank you again!

Marisa

--- In FLASHmacromedia@(protected), peter.ginneberge@(protected) wrote:
> grrrr, darn 'CTRL+S'.
> Sorry, previous message got sent too early by accident...
>
> I ended up saying that you can either assign a function to an onRelease event
or
have it point to a function.
> The latter is handy in case multiple Buttons/MovieClips have to do similar
stuff.
>
> Instead of:
>
> button1.onRelease = function (){
>   trace("hello world");
> }
> button2.onRelease = function(){
>   trace("hello world");
> }
>
>
> // you can write
>
> var helloFunction:Function = function(){
>   trace("hello world");
> }
> //
> button1.onRelease = button2.onRelease = helloFunction;
>
> One important thing to note here is that the scope inside the helloFunction
is not
the timeline it is written in, but the timeline of the instance invoking the
function.
> In the above case, when button1 is clicked, 'this' inside helloFunction will
point to
button1. And when button2 is clicked, 'this' will point to button2. So,
assuming the
code is written in the main timeline, to point to the main timeline you'll have
to use
this._parent inside helloFunction.
> In case you have multiple instances calling the same function and you want to
do
something slighlty different depending on which instance invoked that function,
you
can use 'if', 'if else' or 'switch' statements to determine which instance
invoked the
function and act accordingly. For instance with Button/MovieClip instances you
can
check their instance names, as in the following:
>
> //NAVIGATION FUNCTION
> var navFunction:Function = function () {
>   // NOTE: scope is instance that has been clicked
>   // main timeline is this._parent
>   var p:MovieClip = this._parent;
>   var name:String = this._name;
>   trace("you pressed: "+name);
>   switch (name) {
>   case "logo_btn" :
>   case "text_home_btn" :
>     p.gotoAndStop("home");
>     break;
>   case "flights_btn" :
>   case "text_flights_btn" :
>     p.gotoAndStop("flights");
>     break;
>   case "hotels_btn" :
>   case "text_hotels_btn" :
>     p.gotoAndStop("hotels");
>     break;
>   case "packages_btn" :
>   case "text_packages_btn" :
>     p.gotoAndStop("packages");
>     break;
>   case "business_btn" :
>   case "text_business_btn" :
>     p.gotoAndStop("business");
>     break;
>   case "booking_btn" :
>   case "text_booking_btn" :
>     p.gotoAndStop("booking");
>     break;
>   case "about_btn" :
>   case "text_about_btn" :
>     p.gotoAndStop("about");
>     break;
>   }
> };
> /
/-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
-- -----
> // assign event handler for each navigation instance
> /
/-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---
-- -----
> logo_btn.onRelease = text_home_btn.onRelease=navFunction;
> flights_btn.onRelease = text_flights_btn.onRelease=navFunction;
> hotels_btn.onRelease = text_hotels_btn.onRelease=navFunction;
> packages_btn.onRelease = text_packages_btn.onRelease=navFunction;
> business_btn.onRelease = text_business_btn.onRelease=navFunction;
> booking_btn.onRelease = text_booking_btn.onRelease=navFunction;
> about_btn.onRelease = text_about_btn.onRelease=navFunction;
> //
> stop();
>
>
> If you put the above code in the main timeline of the first scene, it will
actually
work and jump to that specific frame label, even if it's in anther scene.
> The problem is though, that this only works in the scene the code is in,
since in
each scene each existing navigation instance (the one in the scene you were in)
is
overwritten with a new one (the one in the scene you jump to).
> You'll have to assign the onRelease event handlers for each navigation item
(the
last 9 lines in the above sample code) in each scene.
> The navFunction however can be invoked from within any scene without a
problem
(that's because scenes no longer exist when a flash file is compiled).
>
> In some cases, scenes can be useful, but most of the time you should avoid
them.
Especially when you have items that are being used across scenes, etc..
>
> In FMX2004 Macromedia introduced 'Forms', which is probably more suitable for
the kind of thing you're doing.
> However, I'm not a big fan of them in their current state. IDE becomes slow
and
compiling takes forever.
>
> regards,
> Muzak
>
>
> marisa_antonaya  (14/04/2004  06:42):
> >Hello,
> >
> >I'm trying to write a function to activate the navigation (both icons and
text) of a
> >website (made 100% with Flash). Each page of the site is a scene with the
same
> >navigation scheme (and the
> >same instance names for the buttons), and to save code I wanted to create
the
> >function on the first frame of scene 1 ("home") and then call it from the
other
scenes.
> >I wrote the function, and the ActionScript checker said it was fine, but the
buttons
> >don't work, even from the "home" scene where the function originates. I'd
appreciate
> >any help with this. Thanks! I'm using MX2004 Pro, BTW.
> >
> >Marisa
> >



-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Server geeks, take heart! If you're sick of wading through
animation & graphics instruction for relevant info., then
Nate Weiss' Macromedia Flash MX Professional 2004 for Server
Geeks is for you. Leave designing to designers and dig into
core concepts to create rich user interfaces, online
advertising, and more.  See www.peachpit.com for more info.
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/FLASHmacromedia/

<*> To unsubscribe from this group, send an email to:
    FLASHmacromedia-unsubscribe@(protected)

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/