PDA

View Full Version : using 'this._x = variable;'


temptation
07-01-2002, 09:11 AM
Hi all,

I am doing a drag and movie and ahave all the starting coords for my clips automatically loading into an array when the movie starts.

Detecting the target works fine and if I use integers with 'this._x' it works fine but as soon as I substitute a variable it just doesn't work. Below, this._y = j; does nothing although my trace proves that j has exactly the value I want.
Help!!

on (release) {
stopDrag ();
trace (index);
var i = _parent.dragmovies[index].xpos;
var j = _parent.dragmovies[index].ypos;
if (this._droptarget == "/t0"){
this._x = 250;
this._y = j;
trace (i + " " + j);
}

}

Patrick

poab
07-01-2002, 10:20 AM
Hi,

sorry, can't download your file (D*mn firewall, server nonsense).

Anyway, your script seems ok. so I think it's the range of the variables and their availability to the script. Try changing your code to this:

on (release) {
stopDrag ();
trace (index);
_root.i = _parent.dragmovies[index].xpos;
_root.j = _parent.dragmovies[index].ypos;
if (this._droptarget == "/t0"){
_root._x = 250;
_root._y = j;
trace (i + " " + j);
}
}

It's not the best practice but if you're variables are created and stored on the _root and accessed on the _root and it still doesn't work, then it's something somewhere else in the movie (I think).

cheers.

temptation
07-01-2002, 10:33 AM
Tried that and it now moves the whole movie as it is using _root rather than 'this' movie. And still it only moves anything when I use a number rather than a variable for the value.

Can't see why it would be a local variable problem as my trace gives the correct values for the variables.

I've tried all kinds of brackets as well and the b****r just won't work.

poab
07-01-2002, 10:42 AM
Sorry-late night, what I should have said is:

on (release) {
stopDrag ();
trace (index);
_root.i = _parent.dragmovies[index].xpos;
_root.j = _parent.dragmovies[index].ypos;
if (this._droptarget == "/t0"){
this._x = _root._x;
this._y = _root._j;
trace (i + " " + j);
}
}

(Yes I'm a muppet).

cheers.

poab
07-01-2002, 10:51 AM
Hold on! Coffee just arrived at my desk:D

If you absolutely want to position things with arrays (no reason not to) this wil work:

On Main Timeline:

mcNames=["mcOne","mcTwo","mcThree"];
mcXPos=[250,350,450];
mcYPos=[200,220,240];

Script in MC:

for(i=0;i<=_root.mcNames.length;i++){
if(this._name==mcNames[i]){
this._x=mcXPos[i];
this._y=mcYPos[i];
}
}

(Making sure that you give the mcs the corresponding instance names.)

sorry for the mistakes,

cheers.

temptation
07-01-2002, 11:14 AM
The way I have set it up The first frame of my movie actually reads the x and coords of each clip that I have placed on the stage and it is this info I am retrieving for the pupose of this test.

The values of i and j when traced show to have been picked up correctly but are not being recognised as numbers by the 'this._x and y lines'.

Spooky but see below, if I define i nad j specifically then the clip moves exactly where I have told it to go. What I am trying is to is ensure that every time I move a clip it will return to where it was at the start of the scene unless it is dropped on a specific target. This has to be an absolute position because if it has already dropped on one of the targets then I can't just send it back to where I just moved it from.

So, i and j are being defined as shown by the trace command but maybe they are being defined as a string from my array. I have tried to convert to numbers but keep getting errors - what do you think?

on (release) {
stopDrag ();
trace (index);
i = _parent.dragmovies[index].xpos;
j = _parent.dragmovies[index].ypos;
i= 290.6;
j= 290.6;
if (this._droptarget == "/t0"){
this._x = i;
this._y = j;
trace (i + " " + j);
}

}

temptation
07-01-2002, 11:31 AM
Cracked it. When I was pushing values into my initial arrays I was setting the xpos and ypos in square brackets and hence as text rather than numbers. Learning all the time............. Thanks for the help POAB - Looks like I'm the Muppet!!

dragmovies = [];
//set up array to input/read details for each draggable clip
function dragdetails (name, xpos, ypos, used) {
this.name = name;
this.xpos = xpos;
this.ypos = ypos;
this.used = used;
}
//array of text for each draggable Movie
dropnames = new Array("Change","Friendship","Challenge","Community Activities","Competition",
"Creativity","Competence","Reliability","Helpful","Excitement",
"Independence","Persuasive","Intellectual Acclaim","Position/Status",
"Large Organisation","Responsibility","Ideals/Principals","Power and Authority",
"Detailed Work","Money","People Contact","Recognition","Security","Stability",
"Work Alone","Pressure");
//load details for each movie
for (var a = 0; a < dropnames.length; a++) {
_root.movienum = "d" + a;
_root.moviename = _root.dropnames[a];
_root.myxcoord = getProperty(_root[movienum],_x);
_root.myycoord = getProperty(_root[movienum],_y);
dragmovies.push(new dragdetails([moviename],myxcoord,myycoord,false));

//test that array has loaded correctly (disable trace for final version)
trace ("Movie " + movienum + " " + dragmovies[a].name);
trace ("x co-ord " + dragmovies[a].xpos);
trace ("y co-ord " + dragmovies[a].ypos);
trace (dragmovies[a].used);
//write text into drag movies
_root[movienum].droptext = dragmovies[a].name;

poab
07-01-2002, 11:44 AM
Glad you sorted it.

As an aside, wouldn't...

if(onlyOnce!=true){
xOrigin=this._x;
yOrigin=this._y;
}
onlyOnce=true;

..on the first frame of each clip do it too?

concrats.

cheers.

temptation
07-01-2002, 12:24 PM
Thanks for the tip. I've set it up in this complicated fashion cause I know no better and I guess I need to practise.

The final movie will give 26 options to be dragged onto eight targets which you can then drag on or off again, either to a temporary holding target or failing that back home to where they started. Once the user has sorted eight selections into the order that they want, a report is created using the text of the eight selections in order.

As a newbie I find that the easy solutions come when I've already gone around the houses and created the most complicated route to a solution on the planet!

Sayonara and thanks again.