SOAP Web Service With Flash CS5 And The Flex SDK
I use Flash CS5 and FlashDevelop. Never got into the Flex Eclipse malarky. Don’t really have the chance since all my clients use the Flash IDE. I like the Flash IDE as it’s convenient for quick graphical mock ups whilst at the same time allowing me to incorporate complex code written externally with FlashDevelop.
So now I’ve justified why I do what I do why am I writing this? Well sometimes there are things in Flex that the Flash IDE can’t do on it’s own. Luckily most of the Flex classes are just that, classes. I’ve found that the majority of the time you can use them in Flash IDE based projects with no problems. Occasionally I have run into walls where certain Flex SWC files are needed and that’s when you’re in real trouble since the Flash IDE chokes when it tries to load those. Luckily the Flex SOAP loading classes don’t fall into that area and are actually quite easy to use.
- The first step is to download the Adobe Flex SDK. For my latest project I picked the Flex 4.1 Update (126.96.36.19976). I chose the full version that’s 169MB.
- Once that’s downloaded unzip it and place it somewhere easy to reference. I put it in “C:Program Files (x86)AdobeFlex SDK”. So inside there I have the ant, asdoc, bin and other directories.
- Now to get code completion in FlashDevelop load it up and select Tools->Global Classpaths then add these two as new options:
C:Program Files (x86)AdobeFlex SDKframeworksprojectsframeworksrc
C:Program Files (x86)AdobeFlex SDKframeworksprojectsrpcsrc
Remembering to change the first part for where ever you installed the SDK to.
- Now you should have code completion and highlighting for the Flex classes in FlashDevelop. Neat-o.
- Time to do something similar in your Flash project in the IDE. With your fla open go to File->Publish Settings->Flash (tab) Then click “Settings” next to the Script dropdown. That should say ActionScript 3.0 coincidentally.
- First choose the “Library path” tab and add the paths to the two precompiled library swc files:
C:Program Files (x86)AdobeFlex SDKframeworkslibsrpc.swc
C:Program Files (x86)AdobeFlex SDKframeworkslibsframework.swc
Don’t close the Settings popup yet though as there’s one more task to do there. The reason we use the precompiled libraries is because it greatly saves on time when compiling your movie. If you wanted to modify the flex source and compile it into your movie then you would add the two paths we used in FlashDevelop in the “Source path” tab and not include the swc files as noted in this step.
- From what I understand this next step is only required in CS5. I don’t remember doing this last time I played with SOAP in CS4. This time around I kept getting the following error message:
C:Program Files (x86)AdobeFlex SDKframeworksprojectsrpcsrcmxrpcxmlXMLDecoder.as:2513: 1061: Call to a possibly undefined method getAttributeByQName through a reference with static type Class.
Took a bit of searching to find a fix as everything seemed alright code wise. Found my solution here and it was quite simple. Go to the “Library path” tab. The top item will read “$(AppConfig)/ActionScript 3.0/libs”. Select that and then erase it by clicking the minus symbol on the tool bar just above it. Seems there’s another XMLUtil class in there somewhere that conflicts with the Flex version.
- Now the SOAP consuming code should compile just fine.
There is an example of actually using the web service a few posts into this thread. I used that as the basis for my SOAP app. It did need a bit of tweaking to work outside of Flex but nothing major.