PDA

View Full Version : can someone understand these actionscripts?


Jay-sixer
04-20-2005, 03:33 PM
MoveUp = function (standClip) {
_global.ring = standClip.stack.pop();
_global.activeRing = _root["r"+ring];
endCount = 6;
dy = (100-activeRing._y)/endCount;
data = {dy:dy, endCount:endCount};
activeRing.dataQuerry.push(data);
activeRing.active = true;
};

dropDown = function (standClip) {
endCount = 5;
dx = (standClip._x-activeRing._x)/endCount;
data = {dx:dx, endCount:endCount};
activeRing.dataQuerry.push(data);
len = standClip.stack.length;
targetY = standClip._y-len*activeRing._height;
endCount = 6;
dy = (targetY-activeRing._y)/endCount;
data = {dy:dy, endCount:endCount};
activeRing.dataQuerry.push(data);
standClip.stack.push(_global.ring);
activeRing.active = true;
_global.activeRing = null;
};

checkPopable = function () {
// trace("check popable");
for (var p = 0; p<3; p++) {
var stand = _root["a"+p];
// trace(stand);
// trace(stand.stack);
if (stand.stack.length>0) {
stand.btn.enabled = true;
} else {
stand.btn.enabled = false;
}
}
};
checkPushable = function () {
for (var p = 0; p<3; p++) {
var stand = _root["a"+p];
len = stand.stack.length;
if (len<1 || _global.ring<stand.stack[len-1]) {
stand.btn.enabled = true;
} else {
stand.btn.enabled = false;
}
}
};

Frame 2:

stop();
init = function () {
a0.stack = [5, 4, 3, 2, 1];
a1.stack = [];
a2.stack = [];

for (var k = 1; k<=5; k++) {
clip = _root["r"+k];
clip._y = a0._y-(5-k)*clip._height;
clip._x = a0._x;
}
};
init();


on (release) {
ringPos = [];
for (var k = 0; k<3; k++) {
var stack2 = _root["a"+k].stack;
for (var j in stack2) {
ringPos[stack2[j]] = k;
}
}
solve2 = function (n, targetPos) {
if (n == 0) {
return;
}
var pos = ringPos[n];
if (pos == targetPos) {
return solve2(n-1, targetPos);
} else {
var spare = 3-targetPos-pos;
var s1 = solve2(n-1, spare)+"M"+pos+targetPos;
for (var k = 1; k<n; k++) {
ringPos[k] = spare;
}
ringPos[n] = targetPos;
var s2 = solve2(n-1, targetPos);
return s1+s2;
}
};
ans = solve2(5, 1);
//------------------------------------
a0.btn.enabled = a1.btn.enabled=a2.btn.enabled=false;
//---------------------------------------
index = -1;
this.createEmptyMovieClip("solver", 2);
solver.onEnterFrame = function() {
if (!_global.activeRing) {
//pick a move
if (upRing.active) {
return;
}
if (index>=ans.length) {
a0.btn.enabled = a1.btn.enabled=a2.btn.enabled=true;
this.removeMovieClip();
return;
}
index++;
moveUp(_root["a"+ans.substr(index, 1)]);
upRing = _global.activeRing;
return;
}
if (!_global.activeRing.active) {
index++;
dropDown(_root["a"+ans.substr(index, 1)]);
return;
}
};
}

This is from a program called Tower of Hanoi, and I simply only understand minor of it, I hope some professionel user of Flash 2004 MX user can help, cause I am using flash 5, so I just don't understand it...Well in the start yes its to functions for Move up for the brick then drop down for the brick else i don't understand, plz help?

Gibberish
04-20-2005, 04:21 PM
this is pretty pointless as all anyone can do is guess by the naming of the variables. Try using the ['as] tags in the post message box to wrap your code in.

Try removing functions from the fla and seeing what it is you cannot do in the swf anymore. So if you take out function moveUp(); and the character cant go up anymore that obviously is used to move the character up.

Also you are skipping the player this seems to be created in. Try looking into MX instead of MX 2004.

ericlin
04-20-2005, 04:56 PM
Sorry, I have already forgot what I was writing.
I should have had comment in the script.

I think, it better not study that script. Script your own.
Basically, it is a simple solution of Tower of Hanoi.

Many lines of script here are for user inter-action.
1. It keep tracing what ring is moving , how many rings are in the poles and what is the size of the ring on the top of each pole. I also tracing out the original position of the ring and what is the destination position to construct the animation of moveUp and dropDown.

2. To click and move, it is assumed that, the ring on the top is to be moved and is the "Active ring". However, if the active ring is larger than other rings on other poles, then this move is not allowable.

In fact, if we remove these two feature, the core script about solution of Tower of Hanoi is not difficult.

This is the whole file:

Jay-sixer
04-20-2005, 08:39 PM
thnx there, yeah I got it from ur file, because I was going to use some inspiration, but i just did'nt understand those ring and active, but what are they just exactly, just to tell it in simple understanding?....anyway nice game! :)