Flash q
- Started
- Last post
- 30 Responses
- ian
Quick question, is there a way to generate graphs in flash dynamically?
Like a bar graph that draws itself based on a variable that can be easily changed.
How easy/hard is this?
- unfittoprint0
you can make a movieclip containing only (for example) a black 10x100 square).
Insert multiple instances of that movieclip, name them differently and control its height by doing something likere:
bar1._height = var1;
bar2._height = var2;
bar3._height = var3;
...you can start from here, and then proceed to more complex stuff.
- ian0
Ah, I thought it might be something like that. Then I load the variables from a txt file and every time i update the txt files the graph redraws itself?
Unfittoprint, youre a star!
Im using flash MX, the original, not 2004, can you recommend a decent book on Actionscript that will give me a good grounding. I know a little but Id like to learn more.
- unfittoprint0
yes, a long as you do something similar to:
myVars=new LoadVars();
myVars.onLoad = function(sucess){
if(sucess){
bar1._height = var1;
bar2._height = var2;
bar3._height = var3;
...
}else{
trace("error"!)
}
}
myVars.load("graph.txt");Regarding the 2nd question:
there can b only 1
http://www.amazon.com/exec/obido…
- ian0
Sweet. I was looking at that book at the weekend, however its eems mucho cheaper on Amazon.
Cheers!
- ian0
hey unfit, Ive done all that scripting, named the variables, debugged it and its reading the variables but its not setting the height of the bars. What could I be doing wrong?
- MR_T0
have you named your MC instances properly?
- ian0
Yup. 3 bars each called bar1 bar2 and bar3.
I dunno what the deal is. When I input the _height value in it sets the height no probs. It must have trouble dealing with the .txt file.
I saved this in Simpletext as graph.txt. Should I be using seomthing else on a mac?
- MR_T0
Put a trace in the succes bit to see if the txt file is being parsed properly
if(sucess){
trace("success!");
bar1._height = var1;
bar2._height = var2;
bar3._height = var3;
}
- ian0
Dammit, traced the success bit and it came out grand but its still doing nothing to the MC's.
Lordy It hate it when it does these kinds of things.
- MR_T0
And the paths are correct
if(sucess){
bar1._height = var1;
...
should it be something else like _root.myMc.bar1._height =
- ian0
Ok heres what Ive got:
myVars=new LoadVars();
myVars.onLoad = function(sucess){
if(sucess){
trace("success!");
bar01._height = var1;
bar02._height = var2;
bar03._height = var3;
}
else{
trace("error!")
}
}
myVars.load("graph.txt");Then the variables are:
var1=10&var2=30&var3=80But it does nothing. Whats the dilly?
- MR_T0
are you targetting your MC instances correctly?
- ian0
yup everythings on the main timeline in the movie, so it doesnt need _root or anything.
When I change the variable in this part: bar01._height = 10 then it sets the bars height to 10 so its finding the MC fine. Am I doing soemething incredibly silly?
- MR_T0
your variable may be coming in as a string and not a value..it may need to be converted.
you may need to do a int(); on the values...actually check that inn the AS dictionary first..that might not be the right syntax as I am pretty shite giving advice off the top of my head
- MR_T0
Don't listen to me..int() has been depricated.
- MR_T0
Number(string);
- unfittoprint0
MR_T's right. any loaded variable is always treated as a string.
- MR_T0
I guessed right it seems
- ian0
OK, so how do I change it so that it comes in as a value?
- unfittoprint0
myVars.onLoad = function(sucess){
if(sucess){
bar1._height = Number(var1);
bar2._height = Number(var2);
bar3._height = Number(var3);
...
}else{
trace("error"!)
}
}
myVars