View Full Version : [FMX]Controlling x positions from one movieclip with 4 buttons
dboers
April 26th, 2004, 04:55 AM
Hi,
I have a text movieclip (service_mc) on the stage for which I need to control 4 different _xpositions (_x = 0, _x = -700, _x = -1400, x = -2100) with 4 button mc's (btn_one, btn_two, btn_three, btn_four).
For these four buttons I already declared the Over, Out, Release and Restore stage in a function:
for (var i in this) {
if (this[i]._name.substr(0, 4) == "btn_") {
setKnop(this[i]._name);
}
}
function setKnop(clip) {
var clip = eval(clip);
clip.onRollOver = function() {
new Color(this).setRGB(0xA10000);
};
}
etc., etc.
For the easing movement of service_mc I declared the following function:
function movoClip (x){
this.onEnterFrame= function(){
this._x += (x - this._x)/5;
}
}
What I like to accomplish is to control the _x positions of "service_mc" with the same buttons. I mean when btn_one is pressed service_mc should go to _x = 0, when btn_two is pressed the _x position from service_mc should change to _x = -700 etc, etc
How to integrate this possibility in the existing function?
scotty
April 26th, 2004, 05:27 AM
Slightly different:
but = new Array();
but = ["one", "two", "three", "four"];
for (i=0; i<but.length; i++) {
this["btn_"+but[i]].i = i;
clip = this["btn_"+but[i]];
clip.onRollOver = function() {
new Color(this).setRGB(0xA10000);
};
clip.onRelease = function() {
movoClip(-this.i*700);
};
}
function movoClip(x) {
service_mc.onEnterFrame = function() {
this._x += (x-this._x)/5;
};
}
scotty(-:
dboers
April 26th, 2004, 06:36 AM
Hi scotty,
thanks for your reaction. I knew it had something to do with an array, but didn't know how to solve it.I have one question about the code. You start the message with Slightly different:
Does this mean that I have to replace part of the code I used with the top part of your code and if so? Which part of the existing code needs to be replaced with which part of your code.
Thanks in advance :)
scotty
April 26th, 2004, 06:40 AM
You can replace the complete code, you only have to add the on Rollout etc.functions (which were not in the code you gave) :)
scotty(-:
dboers
April 26th, 2004, 07:04 AM
This is the code as I have it now.Can you please have a look because only btn_four is working. When pressing btn_four service_mc dissapears from the screen. The other four buttons aren't working
function movoClip(x) {
service_mc.onEnterFrame = function() {
this._x += (x-this._x)/5;
};
}
but = new Array();
but = ["one", "two", "three", "four"];
for (i=0; i<but.length; i++) {
this["btn_"+but[i]].i = i;
clip = this["btn_"+but[i]];
clip.onRollOver = function() {
new Color(this).setRGB(0xA10000);
}
clip.onRollOut = function () {
if (!this.pushed){
new Color(this).setRGB(0x333333);
}else{
new Color(this).setRGB(0x000073);
}
clip.onRelease = function () {
_root.resetBut();
this.pushed = true;
this.useHandCursor = false;
new Color(this).setRGB(0x000073);
movoClip(-this.i*700);
}
}
}
function resetKnop() {
for (var i in this) {
if (this[i]._name.substr(0, 4) == "btn_") {
var clip = eval(this[i]._name);
clip.pushed = false;
new Color(clip).setRGB(0x333333);
this[i].useHandCursor = true;
}
}
}
Thank you in advance
scotty
April 26th, 2004, 07:31 AM
The onRelease was outside
dboers
April 26th, 2004, 07:32 AM
Hi scotty,
I made a simple example with the code included:
http://www.testfolder.com/moveText.htm
Thanks in advance
scotty
April 26th, 2004, 07:32 AM
The onRelease was inside the onRollOut function;)
for (i=0; i<but.length; i++) {
this["btn_"+but[i]].i = i;
clip = this["btn_"+but[i]];
clip.onRollOver = function() {
new Color(this).setRGB(0xA10000);
};
clip.onRollOut = function() {
if (!this.pushed) {
new Color(this).setRGB(0x333333);
} else {
new Color(this).setRGB(0x000073);
}
};
clip.onRelease = function() {
_root.resetBut();
this.pushed = true;
this.useHandCursor = false;
new Color(this).setRGB(0x000073);
movoClip(this.i*700);
};
}
Also noticed you've got a resetKnop function, but call a resetBut...?
scotty(-:
dboers
April 26th, 2004, 07:54 AM
Thanks four your explenation. 90 % is working now :) Only btn_four isn't. The rollOver, rollOut and Releaeare working. Only btn_four isn't controlling service_mc :h:
dboers
April 26th, 2004, 07:58 AM
Sorry my mistake It is working now :)
Thanks again ;)
scotty
April 26th, 2004, 09:45 AM
You're welcome=)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.