View Full Version : I give up .....(loadvariables)
stephenF
11-15-2001, 06:50 AM
I've had this problem before, and posted, but it sounded like no-one had heard of it before. I hoped it wouldn't come up again, but here it is...(he he he he ha ha ha ha)
I was trying to get variables into an MC2 embedded in another MC1, and it wouldn't happen (same old story, judging by past posts). On the first frame I had:
loadVariables("some.txt", _root.MC1.MC2)
I also tried
loadVariables("some.txt", _root.MC1.MC2.text1)
still wouldn't happen. In desparation, I dragged the first keyframe of MC1 back to frame 1 of the movie, and suddenly MC2 could see the variable. Further tests showed that the variable would only appear when the loadVariables script was at the same frame as the movieclip (ie, they had to overlap in some way). This movieclip appears later in the move at the end of a motiontween (alpha) - so there's another keyframe at the end. Even if the tweened part sees the variable, the new keyframe doesn't unless I repeat the loadVariables code level with it.
So it works, but this can't be right. Can some kind soul help??
don't know 100% if this is correct, but i know a slew of folks will correct me if i'm wrong...
if you do mc1.mc2.loadVariables("mytextfile.txt"); in frame1, but mc1.mc2 doesn't exist until frame5, then how can it load the variables? make sure the mc you want to apply action to exists before you try to apply the action.
stephenF
11-15-2001, 11:09 PM
I wondered this, and it's certainly the way it's behaving. But I think the loadVariables action is supposed to load for the whole movie (unless you tell it not to), so that it's waiting to load into the mc that comes into existence. Otherwise, how could you ever preload variables unless you're just using them on the main timeline?
20 Ton Squirrel
11-21-2001, 07:31 PM
In Flash you can only perform actions on objects/variables that exist within the scope of the current keyframe. Thus if you have a MC that exists somewhere down the timeline you can't preload variables into it.... that's like trying to pass a dish over to someone who is still walking over to you. *CRASH*
Another solution might be to load the variables into the _root or an already existing MC... you could juggle the data around from there.
Don't forget to swonk (http://www.actionscripts.org/forums/showthread.php3?postid=20676&t=4982#post20676) your textfile in... you can't perform actions on data that hasn't finished loading, of course.
stephenF
11-21-2001, 09:32 PM
Thanks to you both (20 ton squirrel and tg)- and for swonk info. Since that post I tried the movieclip loadvariables, which works fine, but there's a bit of a wait for them to load when online. So, what I need to do is what you said, load the variables at _root, use swonk, and get them into the MC from there. Trouble is, I'm very new at this, and programming in general, and I might take ages to work it out. So at the risk of being a nuisance, once the variables are loaded into _root (or another MC), how do you manipulate them into the MC that loads later on?
stephenF
11-23-2001, 05:37 AM
I did the most obvious thing, and did:
loadVariablesNum(text.txt, 0)
then later, level with the MC, did
_level0.MC1.MC2:text1=text1
to my surprise this worked very nicely, and now there are no odd pauses with the variables. Thanks again...
jkd77
11-29-2001, 08:30 PM
I must be the most dense person to ever attempt this, but I've read all through the posts here and I can't get this loadVariables to work.
I tried that swonking bit, (even though I've seen 2 or 3 working examples that didn't use such a method), and I still can't get this to work.
In the first layer of my scene at the _root level I have the following actionScript located at Frame 1:
loadVariablesNum ("angelicoFra.txt", 0);
On frame 3 of said location I have:
if (EOF != "1") {
gotoAndPlay (2);
}
(This was what I understood (or misunderstood?) to do from the swonking code.)
At frame 1 in a different layer I have a movieClip instanced as "main_clip", inside of main_clip at frame 1 I have a "text" layer upon which resides another movieClip entitled "famous_text".
At frame 1 inside famous_text I have the following actionscript:
loadVariablesNum (_root.main_clip.famous_text.angelicoFra.txt=angel icoFra, 0);
*Believe me, I've tried numerous variations of this all day and NOTHING has worked. I wouldn't think such a thing would be so difficult to accomplish...
If anyone can lend me a hand in this I would greatly appreciate it. I'm very green at this stuff so treat me like a 3rd grader.
Thanks,
-Paul
(If need be, I can attach said FLA file upon request...)
here are some possibilities
1. run your fla in test mode, goto and select the menu 'Debug'
click 'list variables'
look for your variable 'eof' or any other variables from the file?
does it = "1"? or "1/r/n"?
if it = the second option, you are not ever getting past the third frame (there is a carriage return and line feed at the end of your file - it can be fixed by removing the carriage return or rewriting the file so it reads '&eof=1&').
2. if your when you do step 1, you do see all of your variables listed, then you don't need to do your second loadVariablesNum, its not going to work the way it is written anyway, so you may as well get rid of it.
i would imagine somewhere you have a text box you want to put your variables into, so if you load your variables into _root, and the text box to display the variables is not on the _root, you will need to assign the value of the variables to the text box.
you can do this from the mc with the text box like
myTextboxName=_root.myVariableName;
or from _root(after variables are loaded) like this
myMC1.myMC2.myTextboxName=myVariableName;
hope this helps, it is starting to feel like rambling to me.
stephenF
11-30-2001, 03:04 AM
You have
_root.main_clip.famous_text.angelicoFra.txt=angeli coFra
in your MC. It won't work from there. This assigns the variable to a path so that flash knows where you want it to go. You could get rid of the swonking for now, and put the above code further along the timeline (say, frame 6). You're text MC has to exist at this frame, too, to receive the variable so extend it to the right if it isn't already. You should see whatever else is in your text MC appear first, then the variable should appear (it takes a second or 2 on a computer, longer on the net) Note that if the above code is too close (in time) to the loadVariables, the variables may not have loaded before the variable can be assigned, in which case nothing will happen (hence swonking). In which case, if you think it's to do with the variables not having time to load, you could drag the above code further to the right (ie; give it more time). Once you've got the variable going where it's supposed to, you can return to swonking. That's what I'd do anyway, so that you're doing it one step at a time.
Note that you can also load the variable straight into the MC with:
loadVariables(text.txt, _root.MC1.MC2)
This goes on the main timeline instead of loadVariablesNum(), and tells flash where to put the variables (ie; _root.MC1.MC2). I used this method, but found that, because MC2 has to exist when loadVariables happens, there can be quite a long pause on the internet. So I found it's better to load the variables on the main timeline, then get them into the MC from there (see earlier posts in this thread).
Also, my understanding is that the text files should have no spaces in them (unless you've incorporated html tags), so that
(EOF != "1") should read (EOF!="1")
Note that I haven't been doing this long, so I wouldn't want to give any bum steers - if the above gives you more trouble than it's worth, go back to the previous posts...
jkd77
11-30-2001, 04:42 AM
I did much of my current editing prior to Stephen's reply, but I need all the help I can get.
Whilst utilizing the debug feature which heretofore I had not used, I finally got those darling text files to load. I'm loading them into a preloader scene, way before the main scene, so they'll load in the beginning with the rest of the content.
Anywho, I've noticed that even though I can load the files as evidenced by the correct value being assigned to the EOF variable, when clicking on a button to send said text file to a mc, I get the following error in debug mode:
Error opening URL "file:///E|/maxProject/"
The code I've assigned to load the text file into a mc from a button in a different mc is:
on (release) {
loadVariables (_root.angelico_fra.txt, _root.main_clip.text_box);
}
Can I not call the loaded file directly by it's name in this fashion? Also, does grabbing the files in a different scene cause a problem?
Are the text files not available across scenes?
I'm using the following to handle this:
loadVariablesNum ("/artistText/famous/angelico_fra.txt", 0);
Once again, I really appreciate all the help. I've been to quite a few other forums with the same problem with no help whatsoever.
-Paul
p.s. - I also finally figured out I needed a dynamic text box to load the text file into. (hey, I didn't know!) :P That box has been set to recieve the contents of a variable marked "text," so that part is taken care of... just FYI.
jkd77
11-30-2001, 01:56 PM
I've assigned the following code to my button:
on (release) {
_root.main_clip.text_box.loadVariables("/artistText/famous/angelico_fra.txt");
}
At least it's not throwing out any error msgs, but it also isn't displaying my text.
Other noticed problem: All scenes run thru ok in debug mode or preview inside flash, but when attempting to preview in actual browser window I get stuck in the preloader scene (where I am attempting to swonk my two text files in.)
Is loading them in a scene prior to my main scene a bad idea? It seems to work in Flash... does it have to do with the file path needing to be absolute in the browser?
-Paul
jkd77
11-30-2001, 02:22 PM
Just attempted to place swonking on main timeline. Everything still works in Flash, variables show correct values in debugger, but text still won't show.
When testing in browser, the loading loop makes all my buttons real sluggish, I can only assume it's still not working in a browser window.
aaarrrgggghhhhh!
20 Ton Squirrel
11-30-2001, 03:06 PM
I had a big diatribe about a bug I found in Flash all written.... then decided against posting it. I don't wanna cry wolf just yet. How 'bout you post up yer FLA and we'll peer into it's murky depths. Don't forget to include any peripheral stuff, too... like your text file.
jkd77
11-30-2001, 03:30 PM
Here 'tis.
In the zip file you shall find,
textTest.fla (with txt file linking changed to link within same directory)
angelico_fra.txt (first loaded txt file)
schlereth_paul.txt (2nd loaded txt file)
Thanx in advance.
(off the subject, just noticed that with multiple file saves to the same file with the same filename, said file incremental increases file size, even after deleting multiple symbols, clips, etc. in said file. When you tell it to Save as... with a new filename, it shrinks the filesize back down. Anyone else ever encounter this?)
20 Ton Squirrel
11-30-2001, 03:33 PM
Yes, I've encountered that in Flash. I make good use of it, too. Doing a Save As, in essence, compacts your FLA back down to its minimal size. Seems like when you bring in stuff and delete it Flash leaves the junk data in there.
Anyhoo... I'll download yer FLA and look at it. If someone beats me to it I won't cry foul. I'm terribly busy at the moment with this so-called real job!
i have changed your code(and files) a little bit, look for my comments in the famous text mc and in the fra angelico button.
hope it makes since. good luck
one more thing, i changed your 'swonk' but forgot to comment it, mainly both were the same...
frame loads a file
skip a frame (but it is not a "blank frame")
frame checks to see if loaded if not loaded go back to frame that loaded the file
should be:
frame loads a file
frame (blank)
frame check to see if loaded if not loaded go back 1 frame (to the blank frame) - otherwise you are reloading the file.
jkd77
11-30-2001, 04:33 PM
Yer tha bomb! I noticed an infinite loop I had mistakenly used with a slightly different swonk technique but I guess I missed it on this revision.
The Embed fonts button, what exactly does that do? Allow font tags to show up?
Once again, thanx. I've been crackin on this fer 3 days... I really appreciate the assistance.
-Paul
20 Ton Squirrel
11-30-2001, 08:02 PM
Glad to see it was solved before I got back, thanks TG. Glad I didn't go the route of whispering bug... that woulda made me look stupider (*snicker*).
The Embed font button is VERY important for the content of your movie. As the name implies, it embeds the font specified for that field into the movie. If you don't embed the font, or at least some of the necessary characters, Flash will substitute fonts for rough equivalents when a user doesn't have them.
For instance, I don't have the font 3HourTour on a project I'm working on with a buddy... he has a Mac so I can't share it. I also can't find it anywhere. Unless the embed option is on when HE publishes the movie, the font shows up as Tahoma on my machine. Make sense?
jkd77
11-30-2001, 09:10 PM
So, if I just click that little embed button, my font will display properly everywhere once published? Ah, crafty.
However, embedded or not, if I need to work on the flash file on a machine without 3HourTour, and then publish it from that machine, what happens then? Does it retain the original embedded font from the original machine with the font?
jkd = jeet kune do (you got it basically)
20 Ton Squirrel
11-30-2001, 09:15 PM
Jeet rocks, had a good friend that was a Kung-Fu/JKD freak... always kicked my arse in sparring. Bruce Lee was the Great One! Never practiced it though... more of a Judo man m'self.
Anyhoo, if you published a movie with an embedded font on a machine that didn't have the aforementioned font, your computer would subsitute it's own. The font is only embedded on Publish, it isn't saved in the FLA unfortunately.
jkd77
12-02-2001, 08:25 PM
Ok guys, how 'bout this:
Instead of loading each file into the main timeline and then using button clicks to send the appropriate text file to the text box, I would like to load and send each text file after clicking a button. Is this feasible?
What I've attempted to do so far is create a new function that looks like this:
function loadText (fileName, EOF) {
loadVariablesNum ("artistText/famous/fileName.txt", 0);
gotoAndPlay (3);
}
This begins a swonk which uses the following to end the swonk:
if (textloaded != EOF) {
gotoAndPlay (3);
} else {
_root.main_clip.text_box.text = fileName;
gotoAndStop (1);
}
This part exists at frame 4 in the same mc as the buttons, function loadText is at frame 2. The loadText fcn takes two parameters sent by the button click, fileName, which is the name of the text file I wish to display, and EOF, which is sent the value of the textloaded variable of said text file.
Is this doable in this arrangement? The reason I don't know is I don't know how to call a custom-made function and thus pass it the necessary parameters. Also, could this function exist in the same mc as the buttons, or should it exist on the main timeline?
Any ideas?
-Paul
// code on release of the button
on(release){
callMyFunctionHere(passInThisVariable);
}
inside your function you will want to change one thing right of the bat
[code]
function loadText (fileName) {
loadVariablesNum ("artistText/famous/"+fileName+".txt", 0);
gotoAndPlay (3);
}
kill the eof... you'll need to figure out a couple of different things here,
1. either all files need a different eof indicator ie. eof1,eof2,eof3 etc, cause once one is true they all will be if they are all just eof.
or leave them all eof and once it is true, and your out of the swonk loop set it back to false or null or undefined so it is not true when you want to load the next file.
2. figure out where you want to put the swonk. you cant put it in the release code, cause you will want two frames, so in one of your mc put a frame label on a frame (something like 'swonkit') then after you do the loadVariables thingy, say mymc.gotoAndPlay("swonkit");
don't know if it will work, just off the top of my head and remembering what your code looked like.
good luck
jkd77
12-03-2001, 02:17 PM
thanx tg.
I moved the function code to a seperate layer on the main timeline so I could call the function in the same fashion from a different set of buttons.
When I type the function, and do this: "+fileName+", flash automatically puts this:
function loadText (fileName) {
loadVariablesNum ("artistText/famous/\"+fileName+\".txt", 0);
gotoAndPlay (3);
}
What's with the extra slashes? I assume the "+fileName+" is used to evaluate the value stored in variable fileName, so as not to try to load file fileName.txt literally.
Do I need special code such as the above to pass a value to the function to be stored into variable fileName?
Also, can't I do the swonk right from the main timeline from the above function, that's why I included gotoAndPlay(3); ?
Thus, frame 3 is blank, and frame 4 contains the following:
if (textloaded != OK) {
gotoAndPlay (3);
} else {
_root.main_clip.text_box.text = fileName;
textloaded = notOk;
gotoAndStop (1);
}
basically i am a pretty plan average not very exciting joe, so once i get used to doing something a certain way, and it works for me, i keep doing it the same way. i always load my files in at the beginning, sometimes i am loading in 4-5 files(.txt) some 30-60 kb in size, and they load so fast, i don't even worry about it, all of my manipulation happens later.
any way here is another possibilty for you...
if i remember correctly the textbox you are loading your files to are inside of a movieclip.?.?. so inside that clip creat a local varialble called myFile or fileName or whateverYouWant.
like this
//frame 1 of mc
var myFile;
var myPath;
myPath = "artistText/famous/"+fileName+".txt";
this.loadVariables(myPath);
//frame 2 is a blank keyFrame;
//frame 3
if(eof){
// assign the value of the var in the text file to the textbox in this mc.
myTextBoxValue=myVariableNameFromTextFile;
//reset the eof value
eof=false;
}else{
gotoAndPlay(_currentFrame-1);
}
stop();
then on the click event you do this.
on(release){
mcHoldingTextBox.myFile="theFileNameGoesHere";
mcHoldingTextBox.play();
}
its kinda rough, did it on the fly so hope it makes sense to you. oh ya, i believe i changed your eof in the files to be different, in this senario, all files would need an eof. (i may be contradicting an earlier post - sorry bout that - my mind changes on the fly continually).
luck
jkd77
12-03-2001, 08:36 PM
This works!!!
In the mc which contains the text box I've got the following:
Frame 1:
var myPath = false;
function loadText (fileName) {
myPath = "artistText/"+fileName+".txt";
this.loadVariables(myPath);
gotoAndPlay (2);
}
(In another layer at this same frame I have a stop(); just in case)
Frame 2: //nada, zilch
Frame 3:
if (textloaded != "OK") {
gotoAndPlay (2);
} else {
textloaded = false;
gotoAndStop (1);
}
On the button I've got the following:
on (release) {
_root.main_clip.text_box.loadText("famous/angelico_fra");
}
I included the directory before the file name and sent it to the fcn to be stored as fileName so I could use the same code with another set of buttons that access files in a different directory.
Thanks to all who made this possible!!!!!!
rainman
01-10-2002, 01:51 PM
Hey
"All scenes run thru ok in debug mode or preview inside flash, but when attempting to preview in actual browser window I get stuck in the preloader scene (where I am attempting to swonk my two text files in.)"
I have the same problem. I don't get stuck in scene but my textfiles are not loaded if i run in broweser (local and on net) But inside flash 5.0 it works fine
http://www.actionscript.org/forums/showthread.php3?threadid=8139&goto=newpost
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.