# Loading a variable to do something

**URL:** https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428
**Category:** Uncategorized
**Created:** [November 2, 2003, 5:38am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428 "2003-11-02T05:38:13Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Freddythunder](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@Freddythunder](https://forum.kirupa.com/u/Freddythunder)
#### Post date: [November 2, 2003, 5:38am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/1 "2003-11-02T05:38:13Z")

</div>

I actually had it working earlier, but accidentaly erased the code that made it work. I have a text file that says:  
taken=x7y7  
Now, what I want Flash to do with that is tell a movieClip called x7y7 to gotoAndStop(2);. I think I used LoadVars() to get it to work. This was the last chuck of code that I tried:

```auto

lv = new LoadVars();
lv.onLoad = function (success){
if (success){
_root.crap = this.taken;
trace (crap);
_root[crap].gotoAndStop(2);
}
}
lv.load("taken.txt");

```

I’m using the individual pieces of code in other places, so I know that it works, just not here. Am I missing something?? Or does anyone have a different idea??

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 5:57am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/2 "2003-11-02T05:57:28Z")

</div>

Well everything works peachy keen for me, but I don’t see why you don’t just use [AS]lv = new LoadVars();  
lv.onLoad = function(success) {  
if (success) {  
\_root[this.taken].gotoAndStop(2);  
}  
};  
lv.load(“taken.txt”);[/AS] Unless you are using the variable \_root.crap for something else?

Also might be a targeting issue, so make sure your targeting is correct.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 9:38am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/3 "2003-11-02T09:38:25Z")

</div>

I think you have to use \_root[\_root.crap] to get it to work that way.

```auto

lv = new LoadVars();
lv.onLoad = function (success){
        if (success){
                _root.crap = this.taken;
                trace (crap);
                _root[_root.crap].gotoAndStop(2);
        }
}
lv.load("taken.txt");

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 3:12pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/4 "2003-11-02T15:12:46Z")

</div>

Only if the code isn’t already on the \_root timeline.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 3:55pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/5 "2003-11-02T15:55:28Z")

</div>

i’d replace by “&taken=x7y7” …

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 5:22pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/6 "2003-11-02T17:22:22Z")

</div>

> \*Originally posted by lostinbeta \*  
> \*\*Only if the code isn’t already on the \_root timeline. \*\*

Yes, but Freddy didn’t say exactly where he placed it, so I figured the best option would be to use \_root anyway. If you place it on \_root, \_root.crap while crap is in \_root will still work right ?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 6:48pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/7 "2003-11-02T18:48:05Z")

</div>

Yes it will.

Although as some may know (or find out), \_root is evil :bad: Relative addressing using this and \_parent is usually the best way to go, it makes the code more portable.

But if it works, then who gives a hooey hooey. 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 2, 2003, 8:04pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/8 "2003-11-02T20:04:14Z")

</div>

Lol, I know, \_root is evil 😛 But well, since ‘crap’ was already placed in \_root, I guessed it didn’t matter.

[size=1]lol[/size] 😛

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 3, 2003, 8:37pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/9 "2003-11-03T20:37:47Z")

</div>

Yeah, my code is on the root _as evil as it may be_. But that movieClip called x7y7 still doesn’t do anything. And ‘crap’ is only used in that chunck of code there. I don’t know what \_root[\_root.crap].gotoAndStop(2); will do, so I’ll have to give that a try.

Eyez - I also had tried the ampersand in front, nothing changed. It’s actually, once working, will be a list printed from a database by a PHP script so it’ll be like:  
&taken1=x7y7&taken2=x4y3&taken3=x9y0…etc  
That way I can change all the blocks that are taken by other people. But thank you!

Lost - All the movieClips (ie ‘x7y7’) are on the main stage so I thought that was how I was supposed to target. I tried 'this’s instead of \_root’s to no avail, but I will try your suggestion. If at all possible, could you post a fla that works like that? That way I could figure it out for sure. Like I said, I had this stupid thing working before, and now I can’t remember how to do it!! Arrgh!! So…Frustrating… ![](http://www.freddythunder.com/test/hair.gif)

Thank you for all your help!!!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 4, 2003, 10:23pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/10 "2003-11-04T22:23:53Z")

</div>

Nope, the code isn’t working and I’m not sure why. The trace window shows that the variable is being recieved, but the movieClip isn’t being told to go to the next frame. Can I use something else?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 5, 2003, 7:42am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/11 "2003-11-05T07:42:04Z")

</div>

What does this output ?

```auto

lv = new LoadVars();
lv.onLoad = function (success){
        if (success){
                _root.crap = this.taken;
trace(_root[_root.crap])
                _root[_root.crap].gotoAndStop(2);
        }
}
lv.load("taken.txt");

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 5, 2003, 5:50pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/12 "2003-11-05T17:50:14Z")

</div>

_‘Undefined’_

In my first example, the output is what it should be ‘x7y7’…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 5, 2003, 6:09pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/13 "2003-11-05T18:09:47Z")

</div>

Then your first code should work :-\ Can we see your fla ?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 5, 2003, 10:23pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/14 "2003-11-05T22:23:11Z")

</div>

Okay Voetsjoeba - good luck my man! I do have to warn you, it’s a bit messy because I’m trying to get the function before the looks. The submit php thing on the button works like a charm, by the way - the only prob is geting the green boxes to turn red with the incomming variable. You’ll see what I’m trying to do. Make sure you make the text file that says:

```php

&taken=x7y7

```

So the the box at x7 and y7 is supposed to turn red on loading. I think you know all this already and don’t know why I keep repeating myself. Sorry. I’ll just post - thanks man!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 6, 2003, 3:32am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/15 "2003-11-06T03:32:16Z")

</div>

I tried it, it worked just fine here :-  
Can I have the url of the php file that generates the variables? 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 6, 2003, 5:10am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/16 "2003-11-06T05:10:17Z")

</div>

What the crap?? Good to see you again Ahmed!! That’s the thing. I haven’t written the PHP for it yet. I just wanted it to work from the text file first, then I could have a PHP script write the text file ahead of time; therefore, I don’t have one.

I guess I’ll try it one more time serverside instead of running it local, but it should work anyway…right???

…my nose is bleeding!! (just kidding :P)

I just tried it server side (same fla in the zip file) and still nothing. I guess I’ll try the grenade, instead.

Thanks for your help guys. Must be my system somehow. I’ll have to try it on someone else’s I guess. Still doesn’t make much sense though.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 6, 2003, 5:27am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/17 "2003-11-06T05:27:43Z")

</div>

yeah it shouldn’t matter whether it’s a php or a textfile you’re loading… I used

```auto
taken=x0y0

```

for the textfile… try that and let me know how it goes 🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 6, 2003, 5:38am UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/18 "2003-11-06T05:38:06Z")

</div>

You know. I’m getting really POed!! I just made this little ditty to see if it’s me. 'Cause I didn’t think it was me!! I paid a lot of attention on our earlier discussions with LoadVars()…So I made a seperate fla with the same [explitive deleted] code and the same [explitive deleted] text file and it works. Why the crap do you think one file works and one doesn’t??

I don’t know…maybe it _is_ time for the grenade…eerrrr!!  
Here’s the test I made that works - tell me if you see something different; maybe I’m just retarded.

Make a text file that has:  
&well=dot  
and call it crap.txt  
Works like a dream…So…Angry… ![](http://freddythunder.com/test/hair.gif)

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 6, 2003, 6:17pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/19 "2003-11-06T18:17:20Z")

</div>

Lol 😛 Seems Flash didn’t like that file 😛

Sorry I wasn’t here fast enough, stupid rules by stupid parents 🅰

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [November 6, 2003, 8:37pm UTC](https://forum.kirupa.com/t/loading-a-variable-to-do-something/34428/20 "2003-11-06T20:37:26Z")

</div>

…Stupid rents…I ran away when I was 18…😛

If anything, think of the bill you don’t have to pay yet!!

I’m gonna redo the whole stupid thing now. Stupid thing!!!
