PDA

View Full Version : dynamic _visible


violetfemme
05-10-2004, 01:47 PM
Hi... New to the boards and I've found them very helpful. There are some great experts here! But I'm trying to do something very similar to what was done in this thread (http://www.actionscript.org/forums/showthread.php3?t=29433). I've got a state map that has counties that are all movie clips (county001_mc, county002_mc, etc....) And a text document that's formatted "&county1=true&county2=false".

Basically what is going on is that if county1=true, then the movie clip county001_mc needs to be visible. If county 2=false then the movie clip county002_mc needs to be not visible and so on and so on.

I've tried working through the examples in the above thread, but it's just not working. Any help? I'm using Flash MX2004

Thanks in advance!

tg
05-10-2004, 02:14 PM
try:
country001_mc._visible=country1;

if your using loadVars() object to load the data into flash, then try:
country001_mc._visible=myLoadVarsObjectInstanceNam e.country1;

violetfemme
05-10-2004, 03:00 PM
Got that logic... hoped it would be that simple! Thanks so much... though I think I'm screwing up the loadVariables now. I can't find any examples that don't include loading the results into a component or text box or something. Any tips?

This forum is for newbies, right? ;)

tg
05-10-2004, 03:06 PM
don't use loadVariables, use the LoadVars() object. its much easier to deal with.

violetfemme
05-10-2004, 03:25 PM
Thanks!

So I've got



myData = new LoadVars();
myData.load("data.txt");
myData.onLoad = function(){
county001_mc._visible=myData.county1;
county002_mc._visible=myData.county2;
};




But it's not working.

I really am a dunderhead when it comes to LoadVars. How can I tell if my data has loaded?

stealthelephant
05-10-2004, 03:45 PM
all is fine part from the onLoad function, it expects a bool var to be passed

mydate = new . . . //ur code
myData.onLoad = function(success){
if(success){
//ur code
}
else
trace("wocca wocca wocca");
};

violetfemme
05-10-2004, 04:00 PM
Thanks! Finally... I understand LoadVars! That's letting me know that the data is loaded... it's just nothing is happening with it.

So it's this part that isn't working.

county001_mc._visible=myData.county1;
county002_mc._visible=myData.county2;

Do I need to parse or something? Do a little dance? Say a little prayer? :p

stealthelephant
05-10-2004, 04:04 PM
use
county1 or
this.county2
no
myData.county1 etc

cos u are inside ur loadvars obj already and u are looking for another obj called myData inside here

violetfemme
05-11-2004, 09:03 AM
It's still not working. How frustrating!

My text doc reads...

&statement1=true&statement2=false

My actionscript is...

myData = new LoadVars();
myData.load("data.txt");
myData.onLoad = function(success){
if(success){
square._visible=statement1;
circle._visible=statement2;
}
else {
trace("I ain't working, yo");
}
}

I've attached both in a zip file. Any more ideas? I know it has to be something simple I'm overlooking!

tg
05-11-2004, 09:40 AM
well, i don't have mx2004, so i can't open you file but this should work, if its finding your file:

myData = new LoadVars();
myData.load("data.txt");
myData.onLoad = function(success){
if(success){
trace(this.statement1);
trace(this.statement2);
}
}


there may be a path problem to your movieclips... if you've got the wrong path to your movie clips, it won't be able to change the visibility.


another problem, and its the likely culprit, is that your variables are being brought into flash as Strings. so myMC._visible="false" won't do what you want (which is myMC._visible=false). if you change true/false to 1/0, it should work, flash will evalute the string "1" to true, and the string "0" to false.

violetfemme
05-11-2004, 09:56 AM
I'm thinking it's probably the string issue, too. So I'll need to parse the load from my text file? I created a textbox and loaded it with the data from data.txt and got "undefined".

I'm a rusty graphic designer that's been thrown into this project with a Friday deadline who knows next to nothing about scripting. I've got stacks of books here on my desk... but they all assume I know how to parse. Is there any guidance/tips you can give? I really appreciate all the help so far.

ps. attached the test files in MX format :)

tg
05-11-2004, 10:19 AM
problem #1:
use this.statement, not just statement. using just statement, flash goes and looks for a variable named statement on the main timeline, that doesn't exist. 'this' tells flash to look for the statement variable belonging to myData.

problem#2:
true and false are strings not bools. so you need to find(or write your own) prototypes to convert strings to boolean values, or change you true/false to 1/0.

once those to problems are handled it works fine.

violetfemme
05-11-2004, 10:30 AM
Just want to make sure I'm understanding you right...

if my text doc reads

"&statement1=1&statement2=0"

Flash will read it as "true" and "false" and no conversion is necessary? Because I tried that and it didn't work.

I really feel like a nimrod here. :(

tg
05-11-2004, 10:56 AM
take a look at this one:



oh yeah, i forgot problem 3:

i appended an ampersand (&) to the end of your data file.
the '&' will trim misc. white space from your variables so they are read correctly.

you flash file wasn't recieving 0, it was getting 0+2 carriage returns/linefeeds.
so it was something like: 0/r/r or 0/n/n

by adding the & it trims off the /rs /ns to give you what you really want.

violetfemme
05-11-2004, 11:44 AM
*mwah!*

I knew it was something I was overlooking... so close...

But thanks SO much! I really appreciate it. You're da bomb!