Archive for September, 2008

Sep 25 2008

Testing for null Objects

Published by under AS 3.0

I am not sure how many Flex/Flash programmers are aware of this fact or also you might call me to be a noob on this point but i discovered this today in AS 3.0, I just use ! to find if the object is null or not and don’t bother testing against another property within that object but sometimes there is no other way around it.

 

Consider the following example,

 

var strObj:Object = "";

//this is standard way of finding if the objects are null or not 

//since the object is initialized there should not be a trace

if (!strObj){ 

    trace("this shouldn't be happening");

}

But the trace statement shows up, it almost seems that Flash is treating this object as null but no if you look at the variable using the debugger the value is not null. So this isn’t the smartest way of checking if the object is null or not specially when you are dealing with strings.

 

Many people recommend doing it differently, like combing it with && for some property check of that object, it would look like this,

var strObj:Object = "";

//this is standard way of finding if the objects are null or not 

//since the object is initialized there should not be a trace

//ofcourse since this is string i am testing for length.

if (!strObj && strObj.length){ 

    trace("this shouldn't be happening");

}

Just something to keep in mind, its not always necessary.
 

2 responses so far

Sep 22 2008

Diving Oil Rigs…

Published by under Diving

This is my favorite dive spot and i try not to miss an opportunity to dive the oil rigs. Of the 45 dives that i have done so far 9 of them have been at the rigs. there are usually not too many fishes to see at the rigs but the other marine life is abundant, mainly anemones, brittle stars, hydroids and other invertebrates. I took my camera with me but it stopped working, I have finally discovered the cause behind this behavior and hope to remedy it or just buy a new camera :D. Sorry folks no pictures on this dive.

 

Woke up at abt 4.45 am and thankfully this time i didn’t wake up to a flat tire :), i reached sea bass at about 6.30 am and the boat was full. There were at least 6 doubles (two tank configuration for diving), three rebreathers and all that technical gear. I thought i was going to be the only one diving in a wetsuit :) but there were others. It is a short ride to the rigs and we were going to dive the farthest called Eureka.

 

A couple of guys were going to do a 4 hour long dive, they were going to dive only to 480 ft, stay there for about 12 mins and then spend rest of the time ascending….its going to be few years, maybe decades before i can even think of going that deep. I buddied up with Alberto rather Dr. Alberto a scientist with JPL. We decided on the dive plan and were not planning to go beyond 110 ft, I couldn’t anyway since i was diving on  32% Nitrox (mixture containing 32% O2 instead of Air which has 21%). 

 

Dive 1:

 

We got into water and the surge wasn’t that bad at all, Alberto and I dove down to 107 ft and we hung there for couple of mins. I forgot to clean my mask and was barely able to see, it wasn’t clear at all. I tried flooding my mask n then clearing it but it didn’t help grrrrr. I started taking pics but then becoz of lack of ability to see i was getting frustrated, my camera also got stuck. I spotted a nudibranch but wasn’t able to take pics. Add to that i was also consuming air pretty fast and it wasn’t a good sign. We ascended making stops and exploring as much as we could and i surfaced with about 200 psi left or maybe less, at this point i was not happy at all. We had to swim little bit and then few mins before we could get to the boat i was completely out of air before we reached it and in the process i must have swallowed quite a bit of sea water, not fun.

 

So it wasn’t a great dive but i learnt some valuable lessons, i could have tried to remove my mask and then wipe it clean underwater but at 100+ feet and 53F water didn’t want to take that chance :). On the bright side the new batteries for the dive light worked great and i used it to full advantage, something i haven’t done before.

 

Dive 1 Details:

Max Depth: 107 ft

Dive Time: 24 mins

Air Consumption: 2200 psi

Max – Min Water Temp: 20.4 – 11.6 C

 

Dive 2:

 

After that not so pleasant experience i decided not to carry my camera and also made sure that i cleaned my mask so that things would be more clear this time :D. This time Alberto decided not to continue with the dive and so i had to buddy up with Glenn and other two guys. Four of us decided to jump into the water as a group.  We were not planning to go beyond 85 ft which was fine since i didn’t want to consume air fast and not get a longer bottom time. 

 

We dropped to about 85 ft and yes i was able to see lot clearer. We explored one side of the rigs and i was using my dive light to find some interesting critters. I also was trying to play with the fishes using my dive light. Saw a lot of big male sheepheads and some of them were about 4-5 ft long.

 

After a while as i was trying to interact with fishes with my dive light, some of them got really interested in it. They did try to bite my dive light a few times thinking it was food, it was fun. I did that for few mins and was so involved in it that i didn’t check my air or depth, but i was at 40 ft and with more than 800 psi left so I was ok. Slowly ascended but for some reason Glenn he didn’t want to stay with the group. I wasn’t too pleased about that fact but i didn’t bother. Three of us surfaced but he was still in water, he didn’t bother to come up with us and we were picked up by the boat. He came up after a few minutes. It was a good dive and it was really fun playing with the fishes. 

 

Dive 2 Details:

Max Depth: 80 ft

Dive Time: 37 mins

Air Consumption: 1975 psi

Max – Min Water Temp: 22.8 – 12 C

 

Dive 3:

 

For the third dive, I didn’t wanna buddy up with Glenn because not only he was distant but also didn’t seem keen on exploring the rigs. luckily he decided to skip this last dive and i buddied up with Mark and Chad. The plan was to dive to 50 ft and then just circle the rigs. I was happy about that. So as planned we dropped to about 50 ft and headed in a different direction as previous dives. It was really cool, on one section of the rigs the anemones all of sudden seem to change colors and they were brownish instead of the usual pink or white. Also saw couple of big star fishes. We spent more time going around the rigs and such so didn’t really play with the fishes this time, but passing between the rig structures is fun as well. 

 

I was the one who was consuming air more rapidly than others and when i was at 500 psi we decided to head up, Mark wasn’t too pleased about it. I could have consumed another 100 before deciding to surface but i wanted to save some air to get to the boat. As soon as i got on the boat after removing my mask i had a bloody discharge from my nose which got me scared but people said it wasn’t anything bad so that got me little settled down.

 

Dive 3 Details:

Max Depth: 56 ft

Dive Time: 35 mins

Air Consumption: 1755 psi

Max – Min Water Temp: 24.8 – 12.8 C

 

One of my favorite things to do while diving the rigs is to stay in water at about 10-15 ft and then just ride the surge. Its fun when you keep on moving up and down along with every new surge of water, i experienced some of it during the first dive thats it. On the surface you have to be really careful to make sure that you don’t hit a steel column above as you rise along with the wave. I am bad with the exact terminology surf, wave or wake not sure what exactly it would be called.

 

We got 3 dives in by 2 pm and we reached the dock by 3 pm, it was cool. Had to attend a house party at Pankaj Uncle’s place in the evening so I was in two minds whether to go home or just change at Romil’s place at USC. I decided the latter, I showered up at Romil’s place to get ready for the party.

 

We stayed at Pankaj Uncle’s place till 4.30 am chit chatting about stuff and then finally after dropping everyone at USC and by the time i got all of my diving gear in tub it was already 5.30, i finally went to bed at about 5.45 am, only 24 something hours after i left for diving :)

One response so far

Sep 05 2008

Using Mapping Services with Flex

Published by under AS 3.0,Flex

For a project i decided to try out the Flex libraries for both Yahoo maps and Google maps as well and they both seem to be pretty cool.

http://developer.yahoo.com/flash/maps/ and http://code.google.com/apis/maps/documentation/flash/

 

After working with examples of both the API’s it was not that difficult to find out which had better features.Lets consider the Visual Aspects first,

 

Speed

When you change the map types, Google emerges the clear winner. you can see it for yourself how fast the maps load. 

 

Zooming

When you zoom in and out, yahoo loads one tile at a time and its not pretty specially while zooming in. Google maps just scales the original image and then when the tiles load it fades out. It could have been better implemented by just waiting for all the tiles to load but they choose not to. Its not 100% clean but still better than yahoo.

 

Dragging

When you drag the map at any level, google maps keeps on repeating the images where as yahoo map just shows one image.It doesn’t matter much but i think its a nice feature to have. 

 

So visually Google is winner but for a Flash developer, Yahoo maps have a lot more to offer.

 

Geocoding

When you geocode something, both work well but the results returned by yahoo provide a lot more information. You can get the state and country information from the city name etc. It is awesome feature which google maps lack and hence for our application we are using yahoo maps.

 

Edit: If you look at the comments, I have been corrected that google does indeed have geocoding features, but i am sorry to say that as of 9th September 2008 the geocoding could use some work. See examples.

 

Search and Traffic

Yahoo maps allows you to get the traffic situation and also perform local search and then display the results on the map. Google map has no such features. 

 

Overlays

Google maps has polygon overlay which yahoo map lacks but then it seems easy to draw everything in yahoo maps using the Flash drawing API’s. 

 

I haven’t looked into changing the look and feel of the buttons etc but it seems to me that both the api’s allow the same. Samples and examples can be found for both, I will be putting one with yahoo maps soon.

 

Examples:

For our application I just wanted the map to move as the region were selected by the city, state and country data. you can check it out here, 

 

Yahoo Maps: Application Source

 

Google Maps: Application Source

 

Please Note: I am using amfphp to get the countries, states (US) and cities data. Also i have edited the keys in the source.

 

If you have both examples open, try to select the country yugoslavia and then see the results. At this point i stopped working on google maps example because it returned everything with yugoslavia. It can be a good thing or a bad thing depending on your application, for me it was bad thing. 

 

So Yahoo which returns me the country works for me, I am using standard city, state and country format to get the geocode results. Yahoo seems to be giving priority in that order.

 

2 responses so far