?
Solved

Flash function available on different frames?

Posted on 2005-02-28
23
Medium Priority
?
231 Views
Last Modified: 2010-04-03
Quick and possibly very stupid question.  How do I make my functions wheter function do_this() or my_mc.onPress = function() available on different frames.  So if I declare these functions on frame 1, everything works fine, but as soon as the movie is on frame 4, 6 or whatever, the functions no longer work.

Suggestions?
0
Comment
Question by:grzegorczyk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 4
  • +2
23 Comments
 
LVL 23

Expert Comment

by:Zeffer
ID: 13423408
that's odd because a function declared on frame 1 is read by the player and stored in memory .. and should be
available to be called from anywhere in the movie.

use an absolute path when calling it .. eg..

function callMe(){
  loadMovieNum("contact.swf", 2);
}

..........

on(release){
 _root.callMe();
}

Z
0
 

Author Comment

by:grzegorczyk
ID: 13423559
doesn't work, though its an btn_nm.onPress = function() which is declared the first frame, when someone presses a button, then the movie goes to that particular frame (the over state of the button).  It works fine if you press the button once, but once you've pressed it and you want to go back nothing happens.  It as thought the function is remembered only once, once it runs, it doesn't want to run again.
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13423997
I see, if the mcbutton is a clip sitting on the stage, your function needs to be on the frames on the stage (not on the frames of your mcbutton)

Billystyx
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Billystyx
ID: 13424019
so, for example, drag your mcbutton from the library onto the stage, then give it an instance name in the properties box, then click on the first frame of the frames your button will span (don't go into edit for the mc, just straight up top in the timeline), then paste your buttonpress function in there, making sure the instance name matches the one you just gave it.

Inside your mc button, all the as code you need is stops at the end of each state (over, hit etc), and labels at the beginning of each state, for you to reference it fro the parent level.

Billystyx
0
 

Author Comment

by:grzegorczyk
ID: 13424080
Well I have a movie clip sitting on the main stage (_root), called "menu_mc", that movie clip contains severall frames with all the buttons on the stage.  So if someone clicks the "about" button, then menu_mc goes to frame "about".  In the first frame of "menu_mc" sit all the functions, declaring what to do when a button is pressed.  so basically a whole bunch of:

 about_btn.onPress = function() {
 gotoAndStop("about");
 }

for every button.  it all works fine, but only once.  I can go to about, then to contact, but if I click about again, it doesn't work. I suspect because the functions are on frame 1 of menu_mc, but now we are on frame 25 (which is "about").  So are you suggesting that I put the code that control the buttons in the _root stage?

0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13424263
not sure. Can you post this anywhere for us to see?
I generally loop around my button mcs and their code, and tell the movie to goto a different frame on a different mc for the actual pages - or load them from outside.
I am of the understanding though that once declared they sit for the life of the mc, but it all depends I guess on exactly how they are arranged.

where for example is frame about in relation to the button/code for the button?

Billystyx
0
 

Author Comment

by:grzegorczyk
ID: 13424314
I will but not for a couple of days, I am away...
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13424354
no worries - I'll be here.

Billystyx
0
 
LVL 8

Expert Comment

by:sokhodom
ID: 13425702
grzegorczyk,

Sometimes it happens to me . The reason is because i forget to assign the INSTANCE NAME(about_btn) to every frame that contains the Button. In your case, for example:when you are on frame 25, you should be able to click on the about_btn but it doesn't work. THis might be due to the fact that in frame 25, the button (about_btn) is not assigned the BUtton instance name yet OR it is simply misspelled. Please check that.

Sokhodom
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 13426947
Hi there.

I disagree with the above comments.

Your functions can be retrieved from anywhere in the movie, if they're declared in the first frame, that is true, however, the reason you are not able to access them is because you've created anonymous functions, i.e. they aren't named.

so what you should be doing is the following:

function about() {
gotoAndStop("about") //check that paths are correct
}

about_btn.onPress = function() {
about();
 }

that should do the trick.

blu.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 13426967
actually, i just recreated what I think you're referring to, and using anonymous functions work as well, might be how you're setting up the timeline, i.e your buttons aren't spanning the distance (frames).

0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13426982
Tht's kind of what I thought - but if that were the case,  grzegorczyk wouldn't be able to press the buttons once the mc had moved away from their frames, because they wouldn't be there.

That's why I figured it would be eaiser to see the fla:)

Billystyx
0
 
LVL 23

Expert Comment

by:Zeffer
ID: 13444475
>> So are you suggesting that I put the code that control the buttons in the _root stage? <<

yes..on frame 1

Z
0
 

Author Comment

by:grzegorczyk
ID: 13476741
Sorry for the wait...

File posted at http://www.kroix.com/menu.fla

Thanks for all the help, i'm increasing the point value to 200
0
 
LVL 39

Assisted Solution

by:blue-genie
blue-genie earned 300 total points
ID: 13476809
your problem is simply that you've set up your timeline wrong. at frame 6, your weddingbutton ceases to exist, so it can't possibly do anything.

you should put all your buttons on one layer that spans the full length (timeline frames) of your movie.

blu.
0
 

Author Comment

by:grzegorczyk
ID: 13476880
Right so the broken up buttons lose referance with the function, so the over states I should control with Actionscript...  otherwise i need to copy the functions into each frame of each button... Yes?

0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13477248
no, you just need to place one instance of each button for the length of the timeline where they will be needed.

If this is a problem with how you have set it up, then you can always set the visibility of the buttons to false at certain stages, and then back again, without affecting their functionality

Billystyx
0
 

Author Comment

by:grzegorczyk
ID: 13477364
full length of the timeline... is that refer to the main timeline of the menu_mc?
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13477789
...I will take a look at your fla tonight
0
 
LVL 18

Accepted Solution

by:
Billystyx earned 500 total points
ID: 13482175
Hello there again, I looked at it, changed it and posted it here:

http://members.lycos.co.uk/billystyx/download.htm


Blu was right - you had them stopping all over the place:)
I deleted a few layers (so I could see what I was doing (they were empty anyway, copied all the buttons onto a layer and then deleted all your layers with buttons stopping and starting on them.
I also changed the buttons to mcs - (just because I', superstitious and that's the way I do it), and set the function on frame1 so you could see it actually works the way we all said it does.

Layout is almost everything - hopefully it helps to see.

Good luck!

Billystyx
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 13484245
are you guys sorted now?

it's a easy fix, you'll see you have extra keyframes on your layers, simply remove those and you'll be okay. (Where the text is no longer a button).

blu.
0
 

Author Comment

by:grzegorczyk
ID: 13486148
Yes, thank you all for your help
0
 
LVL 18

Expert Comment

by:Billystyx
ID: 13486293
no worries
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question