Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-06-2003, 08:18 AM   #1
vosgien
member
 
Join Date: Dec 2001
Location: France
Posts: 923
Default indexOf() syntax - help please !!!

Hi,
I have a bunch of mc's, instance name is 1st, 2nd 3rd and so on.
I want to display the names in a textBox ( called label) as 1, 2, 3, and so on.

So my code is/should be

label = _name.indexOf( what should I put in here to remove the last 2 letters )

if I put label = _name.indexOf("st");
this works well with 1st, but (obviously) not with 2nd

I have done search here and looked at the AS dic, but cannot find what I am looking for

Any help, as ever, greatly appreciated

Cheers

Vosgien
vosgien is offline   Reply With Quote
Old 02-06-2003, 09:16 AM   #2
linckx
indeed
 
linckx's Avatar
 
Join Date: Aug 2002
Location: Olen, Belgium
Posts: 2,058
Default

isn't it possible to give your mc's all names like

myMc1
myMc2
myMc3
myMc4
myMc6

?

it'll save you a lot of crap adressing them...

robin
linckx is offline   Reply With Quote
Old 02-06-2003, 09:40 AM   #3
vosgien
member
 
Join Date: Dec 2001
Location: France
Posts: 923
Default

Hi linckx,
Nah, - the way it works is that all my mc's are buttons, inside each one is a label, when a user clicks a button I want another textBox populated like this:

this.label= _name
onRelease = function(){
myOtherTextBox = "_name";
}

Now, my mc's are called ( at the moment) mc.1st, mc.2nd mc.3rd and so on, this populates myOtherTextBox exactly how I want it but not the mc's.
What I want is for the label ( in the mc ) to show "1";
and myOtherTextBox to show 1st - this means either taking off or adding the string "st" or "nd" or "th" or "rd"

I have an idea it means writing an if/else argument or perhaps a while loop.

Thanks for the input - any other ideas very welcome

Cheers

Vosgien
vosgien is offline   Reply With Quote
Old 02-06-2003, 09:44 AM   #4
linckx
indeed
 
linckx's Avatar
 
Join Date: Aug 2002
Location: Olen, Belgium
Posts: 2,058
Default

well, I'm not the scripting hero

--fiddles with his fluffy pink rabbit slippers while whispering to himself 'you know you will be in 5 years, giving himself a little comfort--

But I wish you good luck with it
I'll keep an eye on the other replies, since it interests me how this is gonna be solved

robin
linckx is offline   Reply With Quote
Old 02-06-2003, 10:26 AM   #5
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy, vosgien... Long time no see...

I am not sure if I am getting it righ... Correct me if I am wrong...

You have series of movieclips which have instance name of 'mc.1st, mc.2nd mc.3rd, ...', right???

If that is true, you are in a big trouble... (I am not the script hero you are looking for either... ) All those instance names contain '.' which is used for the dot syntax, so there is a chance when Flash will burst out and say no way sooner or later...
So, I think it will be a good idea to name them to be something like this... 'mc_1st, mc_2nd mc_3rd, ...'

Having said that, what is it you want to get from those instance names??? Is it 'mc_1' from 'mc_1st' and 'mc_2' from 'mc_2nd'??? Or, Is it '1' from 'mc_1st' and '2' from 'mc_2nd'??? At any rate, you can use substr() function to do the job...

theLabel = _name.substr(0, 4); ---> mc_1
theLabel = _name.substr(3, 1); ---> 1

Know what I mean??? I hope this is what you are looking for... and let me know if this is what you are looking for...

(I am not sure if 'label' is a keyword or not, but I know that I use 'label' for the combobox component, so I just changed it to 'theLabel' so that it won't confuse Flash...)
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 02-06-2003, 10:50 AM   #6
vosgien
member
 
Join Date: Dec 2001
Location: France
Posts: 923
Default

Hi Jason
Yeah, I've still been around, just don't post as much as I need to - whiich could mean I am getting better at this coding thing or I have learnt how to use the searh facility better (lol!!!)
Well, you are right, however in an effort to explain myself clearly I have in fact confused the issue.
Forst of my mc's are called ( in the instance box)
1st 2nd 3rd 4th and so on ( it is for a Flash diary)
the code on the mc is
this.label = _name

therefore the textBox in my mc shows exactly that, but I want it to show 1 2 3 4 and so on
However in myOtherText box, when the button (mmc) is clicked I want it to show 1st 2nd 3rd 4th and so on.
So, I can leave my mc instance names the same and find away of removing st nd rd th etc, OR I can renames my mc's 1 2 3 4 and find away of adding st nd rd th etc etc

Your code does work, but I cannot find the right number (to go in the brackets) to remove or add the offending text.
The whole idea of doing it this way was that I could write on line of code as above - somethings are never as easy as they look !!!

Cheers

Vosgien

p.s. when I say I do not post as often - I do try and answer Q's as often as pos - like many people on this forum, I would never have got ads far as I have without the help of others
vosgien is offline   Reply With Quote
Old 02-06-2003, 11:26 AM   #7
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Um... Okay...

If your MC's intance names are '1st 2nd 3rd 4th', you can say
this.label = _name.substr(0, 1);
to show '1, 2, 3, 4' to the text field...

Yes... You can go backward, but if you go backward, you will be needing lots of if statements to add different postfixes, so I'll stick with what you have if I were you...

Let me know if it works for you...

Glad that you are trying to help other people... Yes... We gotta do what we gotta do to help othere... No doubt about it...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 02-06-2003, 12:12 PM   #8
vosgien
member
 
Join Date: Dec 2001
Location: France
Posts: 923
Default

Hi,
Yeah, I tried that, and played around with different numbers, but it throws up its own problem in that there 31 mc's( for the month)
called 1st to 31st - so, obviously once we get over 9th it doesn't work.
I think I will have to write an if/else argument something like

if (label==3 characters){
label=_name.substr(0,1);
} else {
label = _name.substr(0,2);
}

Not sure of syntax here, but, believe it or not, the point of the exercise is to minimise my code as much as possible, so if I have to write just the one argument, that'll be OK - won't it ? (lol!)

Vosgien
vosgien is offline   Reply With Quote
Old 02-06-2003, 12:23 PM   #9
freddycodes
Master of Nothing
 
Join Date: Dec 2002
Location: San Diego, CA
Posts: 2,468
Default

AS a rule of thumb, object names should never start with a number, Flash is probably one of the only ones that will let you get away with it. Can't you set a variable in each clip for the labels you need. I mean are you dynamically creating these or are they already created and on the stage? Name them something different like mc1, mc2, mc3


In the mc

ActionScript Code:
this.label1 = "1st"; this.label2 = 1;

Now you can access those variables onRelease, unless I am missing something it should be more efficient this way.
freddycodes is offline   Reply With Quote
Old 02-06-2003, 12:25 PM   #10
vosgien
member
 
Join Date: Dec 2001
Location: France
Posts: 923
Default

Hi,
OK, I got it, this little if/else jobbie does eactly what I want - hope your are still folloing this thread linckx........

Thanks for all your help Jason, much appreciated.


if(!_name.substr(0,2)){
this.label = _name.substr(0, 1);
} else {
this.label = _name.substr(0, 2);
}

Cheers

Vosgien
vosgien is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:24 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.