View Full Version : Variables and input text
Sarah012
09-26-2003, 12:36 PM
I am having trouble getting started with a script, perhaps someone could point me in the right direction.
I am creating a movie in which an object moves around a grid based on the x and y co-ordinates that are typed in by the user. I have set up a grid in which each space has a movie clip which are named by its (x,y) co-ordinate [For example:
"0_-2"] I have also created two input text boxes. One for the x variable and one for the y variable. I would like to create a script that moves a circle to a specific space on the grid based on the values typed into these input boxes.
I believe a need to start with a function that relates the value in the x box to the first part of the instance name of my target clip and the value in the y box to the second part of the instance name. Then move the circle to that target clip.
I hope this makes sense. Any suggestions would be appreciated.
Thanks
webguy
09-26-2003, 12:43 PM
You can't start an instance name with a number.
However moving an object based on input is fairly simple. Is that all you are looking for? Let me know, I'll drop an example for ya.
webG
junahu
09-26-2003, 12:45 PM
Not too sure about making functions but the rest is easy enough.
set the two text boxes as input text. In the variable box for the first text box enter _root.myxvar and the second _root.myyvar.
attach this to the movieclip.
onClipEvent(enterFrame)
{
_x = _root.myxvar
_y = _root.myyvar
}
And that's it. Hope it's what you wanted.
Sarah012
09-26-2003, 12:53 PM
Yes, I suppose the first thing I will need to know is how to is how to move an object based on input. I should mention though that the x and y values that are being palced in these boxes will refer to the graph I have drawn and are not the "real" x, y valuse I want to move the object to.
webguy
09-26-2003, 01:00 PM
can you post an example? Your explaination is a little vague, actually my imagination is spacious, that is the problem :D
But what you will need to know to accomplish this is functions, and input text fields.
something like dis:
moveClip = function (id,xPos,yPos) {
id._x = xPos;
id._y = yPos;
}
mc.onPress = function () {
// get the values from the text fields.
xPos = myTextX0.text;
yPos = myTextY.text;
//pass them to the function
moveClip(theMC,xPos,yPos);
}
Kinda see where this is going?
webG
Sarah012
09-26-2003, 01:10 PM
This may make more sense:
Each space on the grid will have a movie clip which will be named "clip_xvalue_yvalue", [for example "clip_0_-3"]
There should be a code the basically says:
the value placed in the x box will be xvalue
the value placed in the y box will be yvalue
the target movie clip will be the instance named when the xvalue and yvalue are swapped into the name "clip_xvalue_yvalue"
then:
the _x of the circle will be set to equal the _x of the target movie clip
the _y of the cirlce will be set to equal the _y of the target movie clip
so the result will be:
the circle moves to the space on the grid occupied by the target movie clip
hope this helps
webguy
09-26-2003, 01:24 PM
hmm.. I keep thinking to myself that their maybe an easier way to do what you are after. Yet I am still spouting possibilities at you. Is it possible to post an example so I can see exactly what is going on?
Anyway, here is my possibility :D
// get the values from the text field
yPos = _root.myTextY.text;
xPos = _root.myTextX.text;
// use these values to target your clip
targetClip = _root["clip"+"_"+[yPos]+"_"+[xPos]];
webG
junahu
09-26-2003, 01:26 PM
Well I'm off. Won't be back till monday so I'll leave you with webguy. He'll have you sorted out soon enough.
Sarah012
09-26-2003, 01:33 PM
I believe that is what I am looking for.
Ishoulde be able to take it from there.
Thank you.
webguy
09-26-2003, 01:38 PM
thanks for the vote of confidence junahu :D
Perhaps though their is a better way to do what you are after, even though I am contradicting my philosophy : "If it works..then it works".
But it seems like you are making some sort of graph, and when a user enters some coordinates in a text box an MC is moved to the coordinates on the graph. Am I close to home on this one? Because it sounds like you have a huge list of MC's placed around the graph that will activate based on user input. Perhaps some simple math, duplicateMovieClip and dynamic positioning will be more effecient. Its entirely up to you, of course. No sense fixing something that is not broken though.
webG
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.