Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 3rd, 2003, 04:53 PM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
setting and recognizing variables internally

I hope I explain this coherently... a little new to Flash.

I have a movie, within that movie I have a frame action that says

if(var=="1"){
gotoNextFrame();
}

in another movie that is a child of that movie, I set var="1" based on a rollOver. Problem is that it doesn't seem that var is getting picked up back in the parent movie. I tried _root.var="1" and _parent.var="1" to no avail.

are variables scoped to the movie that sets them? Is there a way to make a variable global?

I think there is something pretty basic here that I am missing.

any advice is appreciated.

Reply With Quote
  #2  
Old February 4th, 2003, 12:17 AM
bambam's Avatar
bambam bambam is offline
macho member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 207 bambam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 40 sec
Reputation Power: 6
I think you are just missing the variable declaration on the root timeline and also the 'var' variable name is restricted - it is used by flash.

just place this on the 1st frame of the your _root timeline:

var testVar;

this declares the variable for later use.

when you want to alter this variable/flag value. Do this anywhere in your movie.

_root.testVar = "1";

this will alter the value.
then anywhere in your movie:

if (_root.testVar == "1")
{
// do something
}

Reply With Quote
  #3  
Old February 4th, 2003, 08:59 AM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
ok tried that and it still doesn't accomplish the desired effect.

I am declaring the var testVar; in the first frame of the root timeline, and the if condition is also in the first frame of the root timeline.

testVar gets updated to "1" based on a user rollover in a nested movie one level down. When that happens I want the root timeline to move to the nextframe. I think maybe I need something like a tellTarget definition or something to put the focus back on the root timeline?

thanks for the help

Reply With Quote
  #4  
Old February 4th, 2003, 09:20 AM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
think I figured it out...

tellTarget is deprecated, so I used the with() statement like this:

var testVar; - declared on the root timeline

then in the nested movie one level down:

with (_parent) {
testVar = "1";
gotoAndStop("frameLabel");
}

this worked

Reply With Quote
  #5  
Old February 5th, 2003, 02:19 PM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
by the way, puttin "_global" in front of your variables will make them global

so

_global.myvar;

will define the variable, and then from then on, we don't refer to it with the _global, but just by it's name (in my case, myvar). although in this case, it sounds like you just needed to target the right timeline (_parent).

cheers,

bret

Reply With Quote
  #6  
Old February 6th, 2003, 10:17 AM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
here's a new question sort of on topic with this thread:

If I set a variable at the root level of the main movie, how do I reference that variable from a external movie that is brought in using the loadMovie() function?

I have tried _parent._root.varName, _parent.scene.varName, etc... havn't been able to pick it up in the loaded swf.

is this even possible?

Reply With Quote
  #7  
Old February 6th, 2003, 11:59 AM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
ok, figured this one out as well:

_level0.varName

Reply With Quote
  #8  
Old February 6th, 2003, 12:09 PM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
sure it's possible, it just depends on how you loaded the movie in. Let's say that you created a variable on your _root (or _level0 - same thing) timeline. so i say in the actions of my _root:

//
//
myRootVar = "something";

this.createEmptyMovieClip("loader_mc",1);
loader_mc.loadMovie("myexternal.swf");
//
//

This would mean that i loaded my external .swf into the movieclip "loader_mc" that is located on the _root timeline. of course, i'm not sure how or where you are loading in the external movie, but bear with me. Try putting this in the timeline of the external movie:

trace(this);


If you run the external movie on it's own, you will see "_level0" in your output. But try running your main movie; when the external movie loads into the loader_mc it's going to trace:

_level0.loader_mc

This means that in order to get to the _root to acces our root variable, all we have to do is go up one level (this code lies in our external movie):

trace(_parent.myRootVar);

now, this will trace the value of the root variable when it's loaded into your main movie. If you run the external movie on it's own, you'll get nothing, because the variable doesn't exist unless you declare it (obviously) and the only pace we've declared it is in our main movie.

So, you had the right idea, instead of saying "_parent._root.myVar" you would only need to reference the _parent clip "_parent.varName". This is assuming that you are only one level from the _root timeline. If you have loaded the movie into a second or third level, you would just preceed your variable with that many more "_parent."s...:

_root.createEmptyMovieClip("loader_mc",1);
loader_mc.createEmptyMovieClip("secondLoader_mc",2);
loader_mc.secondLoader_mc.loadMovie("external.swf");

in order to access the _root from the external clip, you would need to say:

_parent._parent.myVar

or you could just take the direct path and say:

_root.myVar
or
_level0.myVar

i hope that helps.

cheers,

bret

Reply With Quote
  #9  
Old February 6th, 2003, 04:46 PM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
bret,

that was very helpful, thanks for your time. Hopefully you can assist me one more time...

I have a movie clip that is nested several levels down. In that clip is a button with the following action:

on (release) {
_root.myVar="1";
_root.gotoAndPlay("myNewScene", 1);
}

the desired effect is when the button is clicked we go back out to the main timeline and jump to the scene "myNewScene". However nothing happens at all. Am I referring to the wrong _root? The movie clip with the button is nested 3 clips deep into the main timeline.

_root.myVar gets updated just fine, but I don't understand why it isn't going to the specified scene.

thanks fer the help

Reply With Quote
  #10  
Old February 6th, 2003, 05:53 PM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
sure, the reason is that you don't need to specify a timeline when you are telling flash to go to a scene. your code should look like:

on (release) {
_root.myVar="1";
gotoAndPlay("myNewScene", 1);
}

And that should work...

hope that helps

bret

Reply With Quote
  #11  
Old February 6th, 2003, 06:45 PM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
yeah, I tried that and it doesn't seem to work, it just replays the current movie that the button is in, within the main timeline of the current scene.

Is there a way, when you test the movie, to have it display the path to a specific movie? So say I wanted to have it show me the path to the instance of the movie clip that held my buttons, which would be something like:

main_movie >first_nested_movie >third_nested_movie >button

thanks again for your time

Reply With Quote
  #12  
Old February 7th, 2003, 01:03 AM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
hey, you could trace the path in the external movie by just putting :

trace(this);

in the timeline of your movie (the third nested movie). If all of your files are in the same folder, when you run your main file (test it in flash) the tracing will still be effective, and it will trace the path to the loaded movie.

i wonder why that didn't work with the scene's though.. i tried it out even before i posted here. make sure that you have the scene name spelled right i guess...

cheers,

bret

Reply With Quote
  #13  
Old February 7th, 2003, 07:46 AM
bakedbean bakedbean is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2001
Location: Boston
Posts: 259 bakedbean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 14 sec
Reputation Power: 7
Send a message via AIM to bakedbean
it must have something to do with the way I have the movie clips set up...

Never was able to jump to the new scene by specifying the scene name, but by giving the first frame of the new scene a frame label, I was able to specify that and jump to it.

thanks for the tip on trace()

Reply With Quote
  #14  
Old March 30th, 2003, 10:39 PM
Zoduati Zoduati is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 1 Zoduati User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If I may...

This is my first post, and it relates closely to the other posts in this thread. I

I am having problem getting a variable to work when clicking on a button link to "Meet Marcus". Here's what I am doing.

1) In my main timeline I am initialising a 'goThere' global variable:

_global.goThere="here";

This is in a frame script on frame 1. (There are only 3 frames in the main timeline, which sits parked on frame 3.)

2) On a button in a loaded movie (loaded to level 10), I am setting the 'goThere' variable to "Marcus" like this:

goThere = "Marcus";
trace("goThere=" + goThere);
trace(this);


Traced output:
goThere=Marcus
_level10.btnMeetMarcus


2) My button script loads another movie into level 10, replacing the current movie, and tries to pick up this variable, like this:

trace(goThere);
trace(this);

Here's my traced output:
goThere=here
_level10


As you can see, I am losing my variable which is returning to its default value. I have no idea why.

If you can help, you'd make my day.

Thanks
Geoff

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > setting and recognizing variables internally


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump
<