FlexFusion

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 :)

April 14, 2008

Returning typed objects to Flex from ColdFusion

Filed under: ColdFusion, Flex, code — Tags: , , , , — Gareth @ 12:22 pm

Back in January I saw Brian Kotek’s post about returning typed structs to Flex. When I first read this article, I wasn’t sure how useful it was (I guess I was getting a little confused with the addition of Transfer and AOP in the article, and figured it was just something for that framework). A few weeks later I came across another article about the same idea, and something clicked and I realized just how brilliant this was.

Previously in order to return a typed object to Flex from Coldfusion, you would usually set up aliasing within both your ActionScript object and your CFC

AS:

[RemoteClass(alias="com.mySite.UserVO")]
public class UserVO {

CFC:

<cfcomponent alias="com.mySite.UserVO">

Then, when you transfer objects back and forth between ActionScript and ColdFusion, they are automagically converted to that specific type (along with all of the methods that go along with them). The only bad thing with this method, is that in order to transfer the CFC VO back from ColdFusion to ActionScript, you have to create that object in ColdFusion. Now this doesn’t create much overhead for one object, but if you query the database and return those query rows as separate objects, you have to createObject on each query row, which is an insane hog of memory and server resources. Plus, ActionScript cannot use any of the extra methods that CF is returning, so really anything other than the CFC object’s properties are just extraneous information.

Using the newly discovered technique, you can return the CFC object’s properties as structs rather than having to use createobject each time. You create the properties of the CFC as keys in the struct, such as

myStruct['firstName'] = "John";
mystruct['lastName'] = "Doe";

All that’s needed is to set one extra key in the struct e.g. myStruct['__type__'] = “com.mySite.UserVO” When the items are returned to ActionScript any struct that has __type__ as a key is automagically converted to an object of that type. What’s even more brilliant is if any items within the struct also have an __type__ (e.g. if the user has a company, and that company is returned as a company struct using the same __type__ methodology) then they also get converted to that typed object, so some sort of recursion is happening also.

Now for the sad news (on my part at least). After spending 3 days trying to get this to work on CFMX7 (I had read in a couple of different places that this supposedly would work in CFMX7), I finally found that it apparently only works via LiveCycle or CF8 (which has Flex Data Services Express, I think). After trying everything imaginable, I ended up just having to write a function to convert the returned data to objects. Now I’m hoping that my company will upgrade to CF8, but I don’t think that will be happening. It looks more likely to be Java + WebORB. I’m not sure if this same capability is possible with WebORB, but I’m hoping it does. Certainly is a nice feature to have. Anyway, hopefully this post will be informative for those with CF8 (or LiveCycle) and save those others with CFMX7 from going down the same path as me for 3 days :)

The original post with a little more details is on the CFTalk Mailing List

April 10, 2008

Weirdness with livedocs

Filed under: Flex, code — Tags: , — Gareth @ 3:12 pm

Lately there has been some strangeness with the Adobe livedocs for Flex. Every now and then the page will just constantly reload in a never ending cycle. This seems to only be happening on on the Flex 3 livedocs.

Update:
Looks like the Flex Doc Team will be fixing the problem soon and will get it working as it once was. They even posted a link to a downloadable version of them (It’s 67MB so be prepared for a small wait). I prefer to use this method for access any documentation rather than going online to access them mainly due to the fact if I’m out and about and don’t have an internet connection (I know, not very common any longer, but still…), then I still have access to the documentation. Plus, the livedocs weren’t exactly speedy to begin with, as they had to load the javascript and frames and all of the other fun they’ve put in there. The local version is nice and quick to open. Hopefully I’ll get a chance soon to write an AIR version using the Flex documentation (something like CFDocs which is very quick and has a nice interface)

April 9, 2008

isDate function for Flex…found!

Filed under: Flex, code — Tags: , , — Gareth @ 9:12 am

Well, sort of…

ColdFusion has a very nice “isDate()” function that allows you to pass in a variety of formats, and check whether the passed in value is a date. I had been searching for something similar in Flex, but had very little success until I started playing around with different functions myself.

I had been writing a custom controller for a datagrid which allowed passing in data from an object or table and displaying it in an editable datagrid. The problem I ran into was that depending on the data returned, trying to set those values back to the object that I was using, caused me some issues (such as trying to set a date stored in a text field, back to the object as a “new Date” value). After trying many different kinds of things, I found that the parse function of date works very nicely.

You can do something like

    if ( Date.parse( myDateField.text ) ) {
        myObj.recordingDate = Date.parse( myDateField.text );
    }

If you pass it a value that is not a valid date, the statement returns false.

Anyway, I had been searching around for a while trying to find something that would allow me to check for isDate and this fit the bill nicely. It also allows you to pass in quite a varied type of date formatting and it still recognizes it. Very powerful feature, it seems.

April 8, 2008

I won a copy of Attest!

Filed under: Flex — Tags: , , , , — Gareth @ 11:12 pm

Yay me! The guys over at pxl designs ran a contest today that gave away 3 copies of their excellent Flex 2 certification practice exam, Attest, for free to anyone who answered 3 flex questions correctly. Apparently they were only medium difficulty as I was able to answer them all correctly :) I had previously only downloaded the trial version and found the questions to be well written, difficult enough to make you think (and question whether you are selecting the correct answer because of the excellent potential alternate answers), with excellent, concise answers explaining why a certain answer was correct over another.

A co-worker has been nudging me to take the Flex certification exam, for nothing other than proof that I know what I’m talking about, or that I can flash my Certification when I’m giving a demonstration to my team :) He already passed his exam with no exam studying, just one year of intense self-study-by-doing. I had been putting off taking the exam month after month, saying to myself “once I download the practice exam and go through it a few times, I’ll take the test”. Well, now I’ve got the practice exam and have no excuses for not taking the certification.

I’ll have to take the practice tests a few times, just to make sure I’ve got everything, and read up on some of the documentation over at livedocs, but after that, I’m certification bound :)

April 5, 2008

Wrapping up my background

Filed under: Personal — Tags: , , , — Gareth @ 10:00 am

This should finish up my technical background and can get on with the good stuff.

After proving that I could actually program given something interesting to do, the web development company promptly offered me a position. It consisted of one man who had been working for himself for several years. I worked on all kinds of projects there, large and small, and was allowed to develop my skills in other ventures, not just ColdFusion. However after several years, I felt myself stagnating and not being challenged enough, so, once again, after getting bored, I decided I should look for something new. I had been looking into going towards something of a more OOP design, and needed somewhere that would allow someone with a self-taught CF background, to begin somewhat a-new but bringing all of the coding background along for the ride.

Enter my current company and Adobe Flex. I had no idea (before beginning the position) how much programming and OOP was involved in Flex and ActionScript. I thought that it was all just Flash (which I never thought of as anything more than a design program). After playing with Flex and ActionScript for a couple of weeks, I’ve got a whole new appreciation for it.  It has challenged me more than anything I’ve done so far, and forces me to rethink my previous procedural style of thinking every day. There always seems to be something that can be re-written better or more logically, or encapsulated to save time later. And on that point, I think this article just about sums up me, my programming, and a good portion of why I do what I do The Nerd Handbook (better than I could explain myself :) )

Anyway, if anyone actually made it this far, thanks for reading and hopefully I’ll have the time and patience (and the code) to post something helpful.

April 4, 2008

A Little Background

Filed under: Personal — Tags: , , , , — Gareth @ 10:00 am

Well, not really too little, but hopefully I won’t bore anyone…it’s all great stuff…really
I learned programming in high school, mainly Pascal on UNIX PCs (yes, we all thought that was way too much money to spend on computers that we were just using to type short Pascal programs on), with some Hypercard on Apple II’s, and some TC Logo on any PCs they had lying around. Before this I had really just tinkered with my old Commodore64 and BASIC, so nothing too crazy. Not seeing any of the potential work or monetary gains in this, I switched gears and went with Biology in college. In my junior year, I realized that I really did not like the biology I was learning (that plus my grades weren’t up to par with being that doctor my mum always wanted me to be), I figured it was too late to change course so I might as well finish up and figure out what I wanted to do after graduation.

I ended up going back home and looking for whatever would earn me some cash, that did not involve manual labor (grocery store stocking and assisting my dad with home repairs taught me early about the benefits of an education). I began working as a temp, then worked as a DBA (well, they called me a DBA, but I don’t think MSAccess really counts, but I still keep DBA on the resume :) ) at a mortgage company. I transitioned to their web department (this involved my boss leaving and them saying “Here, you have to do the web site now as well”). Luckily they hired a company using ColdFusion to develop their external site, as I had been having fun with classic ASP before that.

I ended up getting bored just working on the intranet (they used frontpage to manage it), and asked if the web development company needed any help building the site. Not ones to turn down free coding help, they jumped at the chance. From here I got to see (and learn) some not so useful coding practices for ColdFusion (pound signs everywhere), but hey, it was a start and I did manage to fix them going forward. I began working with CF4.5 with MSAccess as the dB, and was well on my way to becoming the CF Guru I am today.

April 2, 2008

Welcome to FlexAbility!

Filed under: Personal — Tags: , , , , — Gareth @ 11:43 pm

Not exactly the most original title for my first post to my very own blog, but everyone has to start somewhere…and yes I do know that it is spelled Flexibility, but this is a better play on words.

I’m writing to this blog partially as a way to post my thoughts, and partially as a way for me to remember things that may have caused me grief while coding in the past.  In writing them, perhaps I can help others through the same issues but with less grief.

I began writing to a blog over at ColdFusion Community and will probably still post there every now and then, but I thought that I would try creating my own rather than going solely through there.  My wife has been asking for a place to post her thoughts so I figured why not keep everything together and just post them both to the family web site.  She hasn’t decided on what she wants hers to be called yet, but once she does, I’m sure she’ll be posting like crazy!

I had originally tried out blogspot/blogger and thought that it would be a simple process to get it up and running.  Initially it was.  I made one post.  I then decided to start copying over some of my posts from CF Community, and that was where my problems started.  At CFC, you could “future date” your posts.  I posted specific days for the blogspot posts, not knowing that that just puts a date on the post, not when it will actually be posted.  After I made 4 posts (apparently too quickly for blogspot), my blog got mark as potential spam.  I got sent an e-mail notifying me that my blog was mark as potential spam, so I went and clicked the “unspam me” link, and went on my merry way.  After 5 days of hearing nothing back, I decided to search around to find another way to notify Google that I was actually a real person and not trying to spam anyone (I’m sure talking about my history would definitely boost the blog spam ratings of someone, somewhere).  Finally I found a link, filled in more or less the same information as before, and waited another 5 days before hearing nothing.  After posting nothing for 10 days, and finally having something to say, I decided enough was enough and started to look around for other solutions.  I then came across WordPress.com

I signed up for an account which, just like blogspot, was quick and easy.  Signed in and started to make my first post.  As I went through my day, I surfed around a bit and found someone who posted that wordpress.com was built off of open source code at wordpress.org  Having a family site written in PHP (for fun, I know, crazy aren’t I :) ), I decided I would try installing the wordpress.org pages and give it a whirl.  Well, after running through the 5 minute installation process, I’m glad I went with Wordpress.  It was such a simple thing to get going, and looks very clean and professional throughout.  Having the PHP pages available is really nice for customization, and as a learning tool.  I’m always looking for ways to improve my coding skills, and what better way than to look through code that has had perhaps thousands of eyes looking at it, improving and optimizing the code.  Plus the simplicity of the administration section will be a boon for the wife.  She wants something that’s easy to use, that she can post her thoughts and pictures and be done with.

This blog will probably be primarily focused on Adobe Flex, Adobe AIR, and Adobe/Macromedia ColdFusion, but have a smattering of personal items, probably some rants, and certainly a PHP issue every now and then.  Hopefully it will become something that will get a regular following, but if it helps one person who was having difficulty coding, then it will have done its job.

Powered by WordPress