Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Actionscript / January 2006



Tip: Looking for answers? Try searching our database.

Buttons instances and their instance name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flamebg - 30 Jan 2006 16:03 GMT
Ok here is the problem.. I have one button with instance name btn11 and when it
is pressed it does sertain thing like opening trough animation 4 other buttons.
You push one of them and a text appears in a text field and the 4 buttons
disappear. So when I push the first button again I want the text that appeared
to disappear so I need to simulate I pushed the one of the four buttons again.
So I want my first button to be not btn11 but btn111 for example. I want to
know how can I change his instance name from btn11 to btn111 and again from
btn111 to btn11 when the text disappears. I know how to do all except how to
change the stupid instance name to what I want it to be in the exact moment. Is
is possible to change it at all ? Cuz I know there might be many instances of
one button and many different instance names.. but in my case I got only 1
button instance and I want to change its names so I can manipulate events
trough that. My code is much more complicated.. but this is the last thing if I
do (to change the instance name during the script and then put it what it was
in the end of it) my script will be complete.
Please help me and if u have any questions just ask..  
David Stiller - 30 Jan 2006 16:42 GMT
Flamebg,

> Ok here is the problem.. I have one button with instance name
> btn11 and when it is pressed it does sertain thing

   So far, so good.

> So when I push the first button again I want the text that appeared
> to disappear so I need to simulate I pushed the one of the four
> buttons again.

   Okay.

> So I want my first button to be not btn11 but btn111 for example.

   This is where I lose you.

> I want to know how can I change his instance name from btn11 to
> btn111 and again from btn111 to btn11 when the text disappears.
> I know how to do all except how to change the stupid instance
> name to what I want it to be in the exact moment. Is is possible to
> change it at all ?

   Really, you're going about this the wrong way.  Instance names are what
allow you to call your instances by name and tell them what to do.  If you
want the button to do something, then not do something, then do it again,
based on other activity in the SWF, then you just need to write your logic
in a way that handles your requirements.

   You might, for example, create a boolean variable (just a true/false
variable) that your button11 checks before it does what it's supposed to.
If the variable is true, it does the thing; if not, it doesn't.  Your other
buttons or activities will simply have to set this variable true or false
along with whatever else they do.

> but this is the last thing if I do (to change the instance name during the
> script and then put it what it was in the end of it) my script will be
> complete.

   I'm not sure what all is going on, but you can certainly make a button
instance disabled (and then re-enabled) by settings its enabled property to
true or false.  Maybe that's all you need.  (Look up the "Button class"
entry in the ActionScript Language Reference [not the Components Language
Reference:  that's a different button altogether] in order to see what
features you have available to you for any given button symbol instance.
Class entries are a lifesaver, because classes define objects, and they
categorize everything about a given obect in one convenient place.  If you
need to see what all can be done with a movie clip symbol, look up the
MovieClip class entry.  Things an object can do are listed under Methods;
characteristics an object has are listed under Properties; things an object
can react to are listed under Events.)

David
stiller (at) quip (dot) net
"Luck is the residue of good design."
Flamebg - 30 Jan 2006 17:36 GMT
well.. what u've said I already know.. the problem is that I want to make one
of these two things:
1) change the name of an instance of a button (Example: my_btn to become
btn111_btn or whatever)
2) when I push a button, the script in it to simulate that another button has
been pushed (Example1: I push button1 which means I've pushed button2;
Example2: if button1 when pushed showes up a cat and button2 when pushed showes
up a dog, I want to make when I push button1 a dog to appear.
So.. can u help me with that one pls..
David Stiller - 30 Jan 2006 17:51 GMT
Flamebg,

> well.. what u've said I already know.. the problem is that I want
> to make one of these two things:
> 1) change the name of an instance of a button (Example: my_btn to
> become btn111_btn or whatever)

   If what I've said you already know, then you wouldn't be trying to
change the instance name of a button.  ;)  I really think you don't need to
change any instance names of anything.

> 2) when I push a button, the script in it to simulate that another
> button has been pushed

   That's fine.  If you assign your button events like this:

function myButtonFunctionA() {
   // do something
}
function myButtonFunctionB() {
   // do something
}

buttonA.onRelease = myButtonFunctionA;
buttonB.onRelease = myButtonFunctionB;

... when you can have button A trigger button B's script easily:

function myButtonFunctionA() {
   // do something
   // then ...
   path.to.buttonB.onRelease();
}

> So.. can u help me with that one pls..

   I think you want to change the instance name of a button because you
don't understand how ActionScript works.  Post the actual code you've
written for two of your buttons, and let's see what you've done.

David
stiller (at) quip (dot) net
"Luck is the residue of good design."
Flamebg - 30 Jan 2006 22:42 GMT
Well.. I don't know if u will understand what it is supposed to happen after
only reading this code :D but I will post it for ya:
First code where the first button is:
textA = ;
textB = ;
textC = ;

my1_btn.onRelease = function() {
    if (tick1 == 0) {
        if (CLT1Variable == 0) {

            _root.subSubButtons1_mc.CLT1FirstButtonAnimation1_mc.gotoAndPlay("slideRight"
);
            CLT1Variable = 1;
        } else if (CLT1Variable == 1 and
_root.subSubButtons1_mc.CLT1FirstButtonAnimation1_mc._currentframe>27) {
            _root.subSubButtons1_mc.CLT1FirstButtonAnimation1_mc.gotoAndStop(1);
            CLT1Variable = 0;
        } else {

            _root.subSubButtons1_mc.CLT1FirstButtonAnimation1_mc.gotoAndPlay("slideLeft")
;
            CLT1Variable = 0;
        }
    }
};
my1_btn.onRollOver = function() {
    my1_btn._name = "btn111";
    for (var j = 1; j<=textA.length; j++) {
        rclip = this;
        rclip.jvar = j;
        rclip.onPress = function() {
            if (tick1 == 1) {
                addText(this.jvar);
            }
        };
    }
};
function addText(j) {
    var removed = 0;
    if (buttonRangeRecognition == "btn11") {
        if (_root.tf.text.indexOf("\r")>=0) {
            newA = _root.tf.text.split("\r");
            for (var k = 0; k<newA.length; k++) {
                if (newA == textA) {
                    newA.splice(k, 1);
                    removed = 1;
                    break;
                }
            }
        }
        if (!removed) {
            _root.tf.text += textA+"\r";
        } else {
            _root.tf.text = newA.join("\r");
        }
    }
    if (buttonRangeRecognition == "btn12") {
        if (_root.tf.text.indexOf("\r")>=0) {
            newB = _root.tf.text.split("\r");
            for (var k = 0; k<newB.length; k++) {
                if (newB == textB) {
                    newB.splice(k, 1);
                    removed = 1;
                    break;
                }
            }
        }
        if (!removed) {
            _root.tf.text += textB+"\r";
        } else {
            _root.tf.text = newB.join("\r");
        }
    }
    if (buttonRangeRecognition == "btn13") {
        if (_root.tf.text.indexOf("\r")>=0) {
            newC = _root.tf.text.split("\r");
            for (var k = 0; k<newC.length; k++) {
                if (newC == textC) {
                    newC.splice(k, 1);
                    removed = 1;
                    break;
                }
            }
        }
        if (!removed) {
            _root.tf.text += textC+"\r";
        } else {
            _root.tf.text = newC.join("\r");
        }
    }
    my1_btn._name = "CLT1_btn";
}

This is the first button .. when u push it it goes back to the main
timeframe.. then goes first into one mc then into second mc in it and plays
animation which shows 3 buttons. After pushing one of them (on(release) {
gotoAndStop(furherframe) on the same timeframe it goes and stops on a frame
further where the next 3-5 buttons follow depending on what of the first of the
3 buttons has been pushed. There I put another script and here it is (IT IS
ONLY FOR THE FIRST FROM THE THREE BUTTONS CHOSEN) :

stop();
textA = ;
for (var j = 1; j<=textA.length; j++) {
    rclip = this;
    rclip.jvar = j;
    rclip.onPress = function() {
        addText(this.jvar);
    };
}
function addText(j) {
    var removed = 0;
    if (_root.tf.text.indexOf("\r")>=0) {
        newA = _root.tf.text.split("\r");
        for (var k = 0; k<newA.length; k++) {
            if (newA == textA) {
                newA.splice(k, 1);
                removed = 1;
                break;
            }
        }
    }
    if (!removed) {
        _root.tf.text += textA+"\r";
    } else {
        _root.tf.text = newA.join("\r");
    }
}

Here is for the second just in case:

textA = ;
for (var j = 1; j<=textA.length; j++) {
rclip = this
rclip.jvar = j;
rclip.onPress = function() {
addText(this.jvar);
};
}
function addText(j) {
var removed = 0;
if (_root.tf.text.indexOf("\r")>=0) {
newA = _root.tf.text.split("\r");
for (var k = 0; k<newA.length; k++) {
if (newA == textA) {
newA.splice(k, 1);
removed = 1;
break;
}
}
}
if (!removed) {
_root.tf.text += textA+"\r";
} else {
_root.tf.text = newA.join("\r");
}
}

Not big difference at all.
So when u push one of the last 3-5 buttons, all the buttons disappear and in
the textField I got the text I want displayed. U can freely add more and more
text from all the buttons and repeat them even. If u remove one all after him
goes back and so on.. I think if u understand this script u should know that. I
haven't written it.. so I don't fully inderstand it. What I think it is
happening is that when one of the last buttons is pushed it takes his name
especially the last number after btn + j ("btn" + j) . So j is the name of the
instance .. example btn1 . It takes the first value from the array. So all till
here is ok. But I want the things this way: when u pick a button and a text
appears in the textfield and all buttons disappear.. a tick is shown next to
the very first button u pushed which indicates u alreay have chosen an option
from all the suggestions. U can easily add more of the suggestions and remove
them anyway u want if the code stays like this, but I want when u push the very
first button.. to remove the tick which is easy and to remove the text from the
textfield which has been chosen.. so here one button has to play the role of
about 12 other buttons. At least I see it this way. In the code above I try to
make my1_btn._name = the button which was pushed. I used a variable and the
variable took the right value but .. I the name of the instance isn't changing
to it. If it did then The very first button could play the role of all 12
buttons in this script.
Ok I hope I am more clear now..
ok waiting for continue :D  
Flamebg - 31 Jan 2006 13:08 GMT
Still need help...
David Stiller - 31 Jan 2006 14:26 GMT
Flamebg,

> Well.. I don't know if u will understand what it is supposed to
> happen after only reading this code :D but I will post it for ya:

   This is a lot (a lot!) of code.

> I think if u understand this script u should know that. I haven't
> written it.. so I don't fully inderstand it.

   This, right here, is almost certainly your problem.  You're using a
script you don't understand.  It shouldn't be surprising, should it, that
you're stuck?  ;)

> Ok I hope I am more clear now..
> ok waiting for continue :D

   Honestly, Flamebg, I have to confess, I'm more lost than ever on what
you're trying to do here.  You're using someone else's code to accomplish
something in your own project, and for all you know, the code you found may
not work at all, may not work for the reasons you need it to, may be
expecting a setup (movie clip hierarchies, perhaps) you don't have.

   I'm trying to piece together what your goals are, based on earlier
posts.  You seem convinced you need to change object instance names, and I'm
more convinced than ever that you simply don't understand what you're up
against.  There is not a way to change instance names in Flash -- it doesn't
make sense to -- but I'm sure there's a way to accomplish what you want.  I
feel like you're a person who wants to smash a bottle in order to drink the
wine, which just doesn't make sense, but you still want to do that.  All you
need is a cork screw.  In this context, your bottle opener is the
ActionScript Language Reference.  I recommend you save your work and start a
new FLA altogether.  Try to rebuild small parts of your project in small,
controlled steps.  Make sure you understand every bit of ActionScript you
use.  It's like playing chess:  it's not a good idea to move a piece unless
you have a reason for doing so.  It's not a good idea to use ActionScript
without undesrstanding what it does.

   I wish I could help you more!

David
stiller (at) quip (dot) net
"Luck is the residue of good design."
Flamebg - 31 Jan 2006 15:23 GMT
Well thank you David :) I succeeded in making work what I wanted and how I
wanted :D I just finished it :D I've written this code here to understand if
there is any way to make it work.. with It I would have solved everything..
like 1 shot 2 rabbits. But it seems like it couldn't be done the way I imagine
it or I just don't have the knowledge .. and I guess whoever looks at this code
won't understand my idea to fix it and make it work cuz it is too complexed
just to read. Well I added 1 more movie clip above that very first button, made
invisible button for all 16+ buttons on 16 frames with the same code used for
them and the same instance names. The code I didn't written I understand 1/2
and that shows to be enough in this case cuz it worked just fine. So I kind of
put 16+ invisible button over (to cover) that very first button so when one of
16+ normal buttons is being pushed he calls the movie clip I added to go to a
frame with that invisible button to cover the very first. And that invisible
button is with the name of the original button being pushed so the code (I
didn't written) works the same as if the original button is being pushed. I did
all that checking how the script I didn't written works. Well If I were u
reading all this I don't know if I would understand what I am trying to say :D
SO here I summarize how it works:
1) Push button1(from all 8 buttons)
2) btn11 , btn12 and btn13 appear using animation
3) push btn11
4) btn111, btn112, btn113 and btn114 show up instead of 2)
5) push btn111
6) a text line appears in the text field, 4) buttons disappear, tick becomes
true (small mc) and an invisible button shows up right over the button1 with
instance name btn111 (this is needed so the script kgab (I think that his name
was) gave me to put the text from textarray depending on the name of the button)
7) if u go over the invisible button the tick inside the square goes white
only if the tick is true, and if out goes black again
8) if you push the invisible button the text from the text field disappear,
the mc where are the invisible buttons goes back to 1 (blank) so u can click on
the button1 again, and the tick goes false (no tick).

Here it is how I made it work :) bad I could do it with code only :(
ok thank u David anyway :)
I think this thread has been answered.. :)
David Stiller - 31 Jan 2006 16:26 GMT
Flamebg,

> Well thank you David :) I succeeded in making work what I
> wanted and how I wanted :D I just finished it :D

   I'm glad to hear that!  :)  I'm afraid I wasn't able to help much at
all, but I'm certainly happy you figured out your own goals.

David
stiller (at) quip (dot) net
"Luck is the residue of good design."
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.