FORUMS: list search recent posts

Check if string contains certain characters

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Marshall Klickman
Check if string contains certain characters
on Apr 30, 2009 at 6:17:10 pm

Hey Guise,

So I'm making a web interface, and I've added event listeners to the main timeline checking for MOUSE_OVER, MOUSE_OUT, and CLICK. The callback function basically checks to see if the current event target is a one of the button movieclips I've set up, through a series of if statements.

At this point I have one if statement set up to check for each button (i.e. if ( == aboutBtn)). I'm trying to save myself some code (and time) and bunch all these conditionals into one if statement, which will check to see if contains the characters "Btn". I thought about using substr(), but the problem there is that my instance names end with "Btn", so they're all at different indexes within the string.

tl;dr - is there a way to check to see if a string contains the characters "Btn" *anywhere* in the string and not just at a specific character index range?

Return to posts index

Pieter Helsen
Re: Check if string contains certain characters
on Apr 30, 2009 at 7:15:33 pm

You can use indexOf("Btn") to determine if the word contains the text Btn. This either returns the index of the character set or -1 if it doesn't contain the character set. Once you have the index, you can use substring(0, the_index_of_the_Btn_string); to substract the name of the button.

Kind regards,

General notice: from now on, I would like to ask everyone to put [AS2] or [AS3] (corresponding to the version of actionscript you are using on your project) in front of their post titles when the question is actionscript related! Please help us help you faster. Thank you.

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved