Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using variables

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi there.
Forgive me, I'm a begginer in flash. Sorry if I'm asking a FAQ or something...
[[I'm using FLASH 5.0]]

What I what to know is hot to:
- set variables:
looks easy but I couldn't do it...
- use variables:
what does represents the value of a variable? In DOS, the name of the variable in "%%" represents its value, like this:
%PATH%
But it seems to be different in flash (why should it be the same?...)

Actually what I'm really up to is: I've got a homepage ( and have put a simple flash menu on it. The page has no frames. I want to when a option is chosen, that it appears different. Letme try to illustrate this:
Code:
<pre>

==FRAME1==                  ==FRAME2==

<home>     -- then you --   [home]
[email me] --  choose  --   [email me]
[links]    --  &quot;links&quot; --   <links>

</pre>
I could do a &quot;on release: 1.get url 2.goto frame#&quot;
But there is a problem. It could be done IF the flash were in a different frame from the rest of the page. But it's not.
So when a option is chosen (they all are links), browser goes to the page chosen. By doing that, it reloads the flash (so it goes to frame 1), killing my first idea.
Then I had another idea (using same example as above):
actions for all the frames:
- goto frame(variable &quot;cp&quot; value)
actions for frame1 button &quot;links&quot;:
- on release: 1.[set variable cp=3] 2.[get url]

Understood? But I don't know how to set a variable and neither how to use its value. I'm not actually sure of the fact that I don't know how to SET variables... I have used the command &quot;set variable&quot;, and then debbuged the movie. The variable didn't appear there. So I THINK it weren't set.
But anyway, the debbuger weren't looking alright anyway (it says nothing at the &quot;Test movie:&quot; box. At the samples that came with Flash, there are some info...)

Please, HELP!
I appreciate any help here

IF YOU DID NOT UNDERSTAND A WORD OF WHAT I WROTE, JUST TELL ME WHAT DOES REPRESENTS THE VALUE OF A VARIABLE

Thanks in advance!!!!!

-- Secret_Doom --
 
erm...i think i understand what u mean... In Flash 5 at least, setting and using variables is as simple as just typing the name of the variable, for example:

Set Variable n = 3 (which flash 5 will reduce to n=3)
Then if you want to use the variable simply refer to it as n, no symbols or % needed.

By the way, i know your flash isnt in a separate frame, but why not make it like that, which would cut out all of your problems..

On the other hand perhaps you could try creating two flash movies, one with the first set of links and one with the second, so when your second page loads it also loads the movie with the second set of options..

Hope this makes sense, and helps a bit :) Nick (Web Designer)
nick.price@misuk.net
 
It depends on your movie, but it could be that the variable isn't available because it's in a different scope.
Try using _root:myvariable

If you try this as an experiment it should give you an idea of how variables in Flash work.
Make a simple 1 frame movie with a text box.
Select the text box and edit the text options dialog to &quot;dynamic text&quot; and &quot;single line&quot;. In the &quot;variable&quot; field, enter the name of your variable, preceeded by &quot;_root:&quot; eg. &quot;_root:myvariable&quot;.
Now bring up the frame actions for frame 1.
use setvariable and target, absoulte to create the following code:
_root:myvariable = &quot;Ahem. Testing, testing.&quot;;

Now test the movie and the variable text should appear in the text box.
You could leave off the &quot;_root:&quot; bit in both cases, but by using &quot;_root:&quot; it makes the variable available to the whole movie.

Hope this helps...
 
Thank you two - HowardMarks & smugdog - very much for the responses!

Now I see with smugdog example that I actually knew how to set variables, just weren't able to see them
Yeah, I could put the flash into a frame, but I don't want to, because:
1. This is (like smugdog said) also a test, to learn
2. Why to simplify things if we can complicate them ? :)

Now talking serious: I realized that I couldn't make a &quot;goto and play frame myvar&quot; (myvar representing a variable), so I did:
Code:
<pre>

frame1:
main actions: stop
              if myvar = 2 { goto and play frame 2 }
actions for &quot;links&quot;: on release { set _root:myvar = 2
                                  get url .../links.html }

frame2:
main actions: stop
              if myvar = 1 { goto and play frame 1 }
actions for &quot;home&quot;: on release { set _root:myvar = 1
                                 get url .../home.html }

</pre>
(Addapted from my flash to same example as first post)

Guess what... The movie produced crashed my flash !
What am I doing wrong? Do you have any other ideas to perform what I'm trying to do (not tricks like puting the movie into a frame :) )

Many many thanks to you guys!
 
Well for one thing, your syntax is incorrect.
Don't know if you just wrote your actions that way on this forum... But here are a few pointers:

In an if statement you must use 2 &quot;==&quot;, as oppose to when setting up a variable where you would use only 1 &quot;=&quot;, as in:
if ( _root:myvar == 1) {
do something;
}
When assigning a value to a variable, you wouldn't use set, you would use this:
_root:myvar = 1;
...or:
var _root:myvar = 1;

As for your stop action:
stop();
And also...
gotoAndPlay (2);


;-)ldnewbie... That's Oldnewbie!
 
Hi there again

Hey unwanted! Thanks! I actually did just post my actions like that on this forum, didn't looked at the movie.
But then I have checked it, and it had an error:
I were really using &quot;if (_root:cp = 1)&quot;
Now I've got it correct.

But it made no difference at all :(

I'll post actions exately as the movie is:

=== actions for frame 1: ===
- main actions:

if (_root:cp == links) {
gotoAndPlay (2);
}

- actions for &quot;links&quot; button:

on (release) {
_root:cp = &quot;links&quot;;
getURL (&quot;batch.html&quot;);
}


=== actions for frame 2 ===
- main actions:
if (_root:cp == home) {
gotoAndPlay (1);
}

- actions for button &quot;home&quot;:
on (release) {
_root:cp = &quot;home&quot;;
getURL (&quot;home.html&quot;);
}


It keeps crashing my flash when I hit CTRL+ENTER...
It's being harder then I though it would be.. :)

No problemo, I'll keep trying

Hey unwanted... Are there any more syntax errors? Maybe that's it.

Oh, yeah! Once I have hitted CTRL+ENTER and before crashing, flash displayed this msg (something like that)
&quot;This script contains errors that may cause you computer to work slowly and loose control. Do you want to proceed Y/N ?&quot;

I'm quite sure the msgs WEREN'T exately like that, but it where something like that.

Thanks everyone for the help!

-- Secret_Doom --
 
Yes! You possibly have more syntax errors... Like with getURL... And you dont have any stop() actions!
Difficult to understand what you're trying to do... And I'm too lazy to re-read and understand your first post!
You can send me your .fla at oldnewbie@hotmail.com
and I'll have a look at it! Otherwise, I can't really help you more than I already did!

;-)ldnewbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top