FlexFusion

May 22, 2008

Adding space before and after parentheses

Filed under: ColdFusion, Eclipse, Errors, Regular Expressions, Uncategorized — Tags: , — Gareth @ 2:22 pm

I had previously written a regular expression that adds extra space within parentheses, so (test) would become ( test ). However, this gets more complex the more parentheses that are added to the mix. ((test)) and (((test))) require a much more complex regex statement to work correctly (and find the correct ending parenthesis to match up with the correct starting parenthesis).

I was rethinking how I did this and came up with a new method. The only difference is that this test will need to be run twice, once for the opening parenthesis and once for the closing parenthesis. As I usually just do a “Replace All”, I figured it wasn’t that much more difficult than doing it the old way (plus this will work for a much parenthesis nesting as a user puts in).

The Regular Expression is:

Find: \((?! |\))
Replace: "( "

remove the double quotes first…I just wanted to make the space visible.

This regular expression means:
Find an opening parenthesis

\(

Then check the next character (but do not include/consume it in the “find”). If it is not a space or a closing parenthesis, match the statement

(?! |\))

This will work on something like:

(((test())))

which, after the first run, becomes

( ( ( test())))

Then the second Regular Expression would be:

Find: (?<! |\()\)
Replace: " )"

remove the double quotes first…I just wanted to make the space visible.

This regular expression means (starting from the right this time):
Find a closing parenthesis

\)

Then check the previous character (but don’t include/consume it in the “find”). If it is not a space or opening parenthesis, match the statement.

(?<! |\()

This will take the previous finished example of:

( ( ( test())))

and change it to:

( ( ( test() ) ) )

By adding the extra space to my code, I think it makes everything a little bit easier to read. This will work for any type of brackets (or any character for that matter). In the first find statement, you can replace the parenthesis in \) and \( with \[ or \] or whatever you want. The same goes for the second find statement. I don’t know why I didn’t think of doing it this way before instead of trying to figure out how to code a really long match for the opening and closing parentheses. It will definitely make my life easier.

April 18, 2008

The supplied index is out of bounds ( image instantiation )

Filed under: Errors, Flex, code — Tags: , , — Gareth @ 11:04 am

A coworker of mine has created a drag ‘n’ drop component that allows dragging between 2 items (base component is a ListBase, so it allows for greater flexibility of the list dataProviders). Today I needed to enable or disable the list components, but all it could do was disable the entire component. If the component was completely disabled, the user would not be able to scroll the list and see all of the items in it. We had decided that rather than just disabling everything, that we would just disable drag ‘n’ drop between the lists and remove the directional arrows that are also part of the component (left arrow pushes items from right to left, and vice versa for the right arrow).

I decided to override the enabled property of the component that this component was extending. Within this enabled, I was checking for initialization, then disabling drag for both lists and making the arrows invisible; however, once I compiled and ran the code I received a

RangeError: Error #2006: The supplied index is out of bounds.
at flash.display::DisplayObjectContainer/getChildAt()

I decided to try running debugger to see if it would give me the line of code that was throwing the error, but to no avail. I had tried gradually removing all of the items that I had added, but nothing worked. I even cleaned out my project and recompiled everything, but still no luck. It wasn’t until I undid everything I had added that it worked (as it should), but when I was testing, I had removed (almost) everything that I had added. The only thing I had not done was delete some image variables that I had moved from a private function to private variables at the top of the page, so I could access them within my “enabled” function. I put all of my code back in again and did not instantiate the image variables when I declared them, but rather in the creationComplete function, and no error.

After finally narrowing it down to the image instantiation, I tried instantiating the images on declaration and in the creationComplete function and, again, no error was thrown, so apparently it has something to do with trying to reference an image variable that is instantiated before creationComplete. I guess this goes hand-in-hand with “only instantiate your variables when you are going to use them”. Now that’s figured out…back to work :)

Powered by WordPress