



Today I had to write some code to search for text that matched various file extensions, this should have been a no brainer of a task. But like some things that sound stupidly simple it caught me out.
If you have a string and you use the search method then when it finds something it will return the position. If it doesn’t then it will return -1. So far so good.
Now I could go into huge detail (I did, but it ended up to wordy/dull, so I just deleted it!).
So if you EVER have to search for a string and your string starts with a period ‘.’ then add a double backslash ‘\\’.
If you don’t then the period will match anything! e.g. you want to match ‘.ra’ and the string contains the word brain then ‘brain’.search( ‘.ra’ ) DOES NOT return -1!
use ‘\\.ra’ for correct results.
Not sure why ‘.ra’ doesn’t work, maybe it’s treating the string like a regEx, I know search can take both a string and a regEx so maybe its not looking at its type and guessing that it should be a regEx?? You can’t step into the code either to see why, so just use the \\
Very annoying!
|
|




Yeah its been ages since I’ve last blogged any code articles (got a few 1/2 done – honest!). Just been very busy in the past several months working with the crew from Jampot. Anyway check out this article where we headline in Engadget. Shows off our new product which can let you build an app in minutes and get it installed on your phone.
Check out the actual Engadget article here.
Check out the fab Jampot team here
And of course check out this to build an app and get it on your phone in minutes.




The application that I’m working on with the guys at Jampot has made the BBC news. Check out the article from the BBC.
http://www.bbc.co.uk/news/uk-northern-ireland-15075450
Also the guys are heading over to the Adobe Max 2011 conference so you’ll be able to see it live and see how easy it is to create a mobile app for all mobile platforms.




Developing for Apple’s devices can throw up a few little quirks that don’t happen when using Android devices.
This one happens if you are using shared objects to store information between sessions.
Basically, you should always call the flush mechanism whether you are adding more data to the shared object or if you are deleting something from the shared object.
What you find is if you have a shared object ‘shared’ with a value shared.data.firstValue = “something”, then you delete that value using
delete shared.data.firstValue;
if you try to access the value firstValue you will get null.
This is exactly what I’d expect.
Then lets say you exit the app and you either kill the app from running in the background or iOS stops it. Then the next time you load the app and access the shared object shared.data.firstValue you will get back “something” and not null.
You must flush the shared object for it to be stored locally, otherwise when the app is killed, the local storage will not have been updated.




Its quite a common thing with Flex and actionscript projects to create an Object and inside that object it will have many properties. Something in your view will be bound to the object so that the view changes with the object. So long as you change the entire object this will work fine.
Where this doesn’t work is if you change a property inside the object.
So if we have something like this
[Bindable] private var myObject : ObjectDataVO; <view:SomeComponent ... data="{ myObject }" ... />
When we set myObject to something the view component gets updated (great so far).
Lets say the myObject has a property text and the view component uses this to display some visual label, then somewhere in the app I change that property, myObject.text = “something else”;
The binding will not trigger as I haven’t actually changed the myObject, just a property inside it.
So how do we fire the binding manually? Well there is the BindingManager class (note this is an excluded class so you’ll not see it in the autocomplete ).
So in this example if I changed the myObject.text property then I could call
BindingManager.executeBindings( this, ‘myObject.text’, myObject );
This would fire of the binding as if the actual myObject had changed so anything listening in will now get updated.




Sometimes I like to put something up on my blog that’s more as of a bookmark for myself as I know I’ll want to look it up at some point. So what I’ve got here is a slack, open cross domain policy.
DO NOT USE THIS IN YOUR PRODUCTION CODE
(unless you really need to and understand why you shouldn’t)
This will get rid of any security issues you may be having while in development.
<?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <site-control permitted-cross-domain-policies="all"/> <allow-access-from domain="*" secure="false"/> <allow-http-request-headers-from domain="*" headers="*" secure="false"/> </cross-domain-policy>




Working on a mobile project I needed to create a renderer for a list, so I choose to look at the IconItemRenderer which extends the LabelItemRenderer. These have been optimised for mobile use so it seemed a reasonable place to start. On the whole they seem like good classes to use, but if you’ve ever worked with the Datagrid/DataGridBase in the past you will probably know about the white square which comes about from the hardcoded #FFFFFF values inside the DataGridBase!
Well the IconItemRenderer and LabelItemRenderer have a similar issue. So lets just say you create a list and you wish to skin the list exactly how you like or use it in a tile layout or something other than vertical then you will find some lines above and below your renderers which look out of place. You can’t get rid of them no matter what property styles you set.
The fix is pretty straight forward but why does there have to be some hardcoded values in something that is meant to be very versatile?
So inside the LabelItemRenderer around lines 881 you will see the following. It uses these values to draw separators whether you like it or not.
// separators are a highlight on the top and shadow on the bottom topSeparatorColor = 0xFFFFFF; topSeparatorAlpha = .3; bottomSeparatorColor = 0x000000; bottomSeparatorAlpha = .3;
So the quickest way of dealing with this is to override the drawBackground function in your own class which is created in LabelItemRenderer. This doesn’t get called from IconItemRenderer so you can quite simple copy the entire function and just remove the separator chunk and do not call super from your function which overrides the drawBackground.
Better still would be to change the hard coded values to styles from a CSS file.
var topSeparatorColor : uint = getStyle( 'topSeparatorColor' ); var topSeparatorAlpha : Number = getStyle( 'topSeparatorAlpha' ); topSeparatorAlpha = isNaN( topSeparatorAlpha ) ? 1 : topSeparatorAlpha;
If you’re setting a Number just remember to check for NaN’s in case you haven’t set a style, uints default to 0 anyway.




The other day I wanted to create a function in a class that would take a Function as a parameter and an Array of arguments. Much like callLater() does, but not doing the whole queuing thing until the next frame.
So how do you call a function that may have any number of arguments. Well here is the code and it should speak for itself.
protected function checkSomethingThenCallOtherFunction( method : Function, args : Array = null ) : void { if( something.length < someMaxLimit ) { method.apply( null, args ); } else { //do something else } }
So how easy is that? Pass in the function and an array of arguments, that’s all.


More Options ...
Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 