Page 1 of 1

[MORE] Flash Variables

Posted: Sat Jul 29, 2006 10:38 am
by tecktalkcm0391
What I am trying to do is use FlashVars. I have HTML like this:

Code: Select all

<param name="flashvars" value="high=62&low=2">
I want highNumber to be = to the value high from above and if its not there highNumber to be =to 40, and the same thing for lowNumber. I have this so far:

Code: Select all

if(high == undefined){
	var highNumber = 40;
} else {
	var highNumber = high;
}
if(low == undefined){
	var lowNumber = 1;
} else {
	var lowNumber = low;
}
Is it right?

NOTE: This code is in a Movie Clip.. if that has anything to do with it?

Posted: Sat Jul 29, 2006 12:58 pm
by neophyte
Syntax looks correct. I'm assuming you are having trouble getting the flashVars in to the movie clip? I'd put a text box so I could print the value of "higher" out to the screen. Then I'd try looking at whether my reference paths were correct. Try doing a full _root.path.to.your.movie.clip. See if that helps.

Posted: Sat Jul 29, 2006 1:00 pm
by tecktalkcm0391
neophyte wrote:Syntax looks correct. I'm assuming you are having trouble getting the flashVars in to the movie clip? I'd put a text box so I could print the value of "higher" out to the screen. Then I'd try looking at whether my reference paths were correct. Try doing a full _root.path.to.your.movie.clip. See if that helps.
Ok, I'll try that and post back, what is the full _root.path.to.your.movie.clip.. i am very new to flash...

Posted: Sat Jul 29, 2006 1:08 pm
by tecktalkcm0391
OK, I made some textboxes on the regular flash animation and they show up. I used this:

Code: Select all

if(high == undefined){
	var highNumber = 40;
} else {
	if(high != ""){
		var highNumber = high;
	} else {
		var highNumber = 40;
	}
}
if(low == undefined){
	var lowNumber = 1;
} else {
	if(low != ""){
		var lowNumber = low;
	} else {
		var lowNumber = 40;
	}
}
highest.text = highNumber;
lowest.text = lowNumber;
Now, I just need them to go into the movie clip.....:( Thanks :)... I'll keep trying, anyhelp would be great!

Posted: Sat Jul 29, 2006 1:25 pm
by neophyte
Getting them into the movie clip will be a reference issue. Try starting from _root I'm sure the flash vars exist there.

Posted: Sat Jul 29, 2006 1:26 pm
by tecktalkcm0391
How do I do that... lol :( Sorry...

Posted: Sat Jul 29, 2006 2:49 pm
by neophyte
It's been a while since I did Action Script like this:

_root represents the main level of the movie.

So I have a variable named "Weasley" in a movie clip. The movie clips instance name is "George". But George is inside a movie clip with a instance named Fred.

So to access "Weasley from the main timeline I would:

Code: Select all

trace(_root.Fred.George.Weasley);

Posted: Sat Jul 29, 2006 2:56 pm
by tecktalkcm0391
ok, well then how would I use that put it in from of the variables or what? I know your prob. like :roll: but sorry..... :?

Posted: Sat Jul 29, 2006 8:16 pm
by neophyte
Okay so the flashvars are associated to the main timeline. If you are more than one movie clip deep you have to build a relative or absolute path to the value you need.

Code: Select all

<param name="FLASHVARS" value="someVar=fubar">

Code: Select all

_root.someVar
That should give you access to the value "fubar".

If you want to copy the value into a variable try this.

Code: Select all

foo = _root.someVar;
If that doesn't do it make sure you flashvar param html is correct.

Posted: Sun Jul 30, 2006 8:53 am
by tecktalkcm0391
Ok this is where I am right now...

I am using the code below now. And this is what happens.... If I don't set any variables in FLASHVARS then it does 0-9 and then if I set high=9&low=0 it outputs numbers 0-9 but with a zero on the end.... anybody know how to fix this?

Code: Select all

if(_root.high == undefined){ 
	var highNumber = 9; 
} else { 
	var highNumber = _root.high; 
} 
if(_root.low == undefined){ 
	var lowNumber = 0; 
} else { 
	var lowNumber = _root.low; 
} 
number.text = Math.round(Math.random() * (highNumber - lowNumber)) + lowNumber;

Posted: Sun Jul 30, 2006 8:55 am
by tecktalkcm0391
After playing around some more I've found that its doing that weird thing to every number if I put in high = 40 and low =1 then i get numbers in the hundreds... is my line:

number.text = Math.round(Math.random() * (highNumber - lowNumber)) + lowNumber;

right when it comes to making a random number between high and low?

Posted: Sun Jul 30, 2006 11:06 am
by neophyte
Not sure on that point. I'd have to do some reading. I've forgotten some of my Flash Math stuff. Keep working it you'll figure it out. ;)

Posted: Tue Aug 01, 2006 5:29 pm
by tecktalkcm0391
neophyte wrote:Not sure on that point. I'd have to do some reading. I've forgotten some of my Flash Math stuff. Keep working it you'll figure it out. ;)
Well I kept working on it and I figured it out. Thanks for all of you help. I had to use Number(); to convert the strings to numbers. So now its:

Code: Select all

if(_root.high == undefined){ 
   var highNumber = Number(9); 
} else { 
   var highNumber = Number(_root.high); 
} 
if(_root.low == undefined){ 
   var lowNumber = Number(0); 
} else { 
   var lowNumber = Number(_root.low); 
} 
number.text = Math.round(Math.random() * (highNumber - lowNumber)) + lowNumber;
The only thing for others is that for the 9 and 0 you don't need to put the Number() around it, but I did just to be on the safe side.

Posted: Fri Aug 04, 2006 7:27 pm
by tecktalkcm0391
NEW QUESTION SAME TOPIC:

OK, well I need to make a loop (which I know how to do) that needs to do this (which I have no clue how to do):

Take arrayval and add the varaiable from the loop to make a variable name in which I can use to call them from flashvars

Ineed something like:

Code: Select all

var arraycount = 3
for(var c:Number=0; c < arraycount; c++){
      array[c] = arrayval#   (<--- where the number is 3 so that I can get the flashvar that is arrayval3)
}
Just like doing $arrayval$c = "hello"; in php