Wednesday, November 11, 2009

Creating in Memory BitMaps from a single image file.

I found this today while looking up information on the new Flex 4 Layout classes. This guy has a single .png file with a bunch of cards on it that he wants to use as individual images in his application. I was pretty impressed with the code, mainly because I had never really thought about it and it's an easy solution.

protected function application1_creationCompleteHandler(event:FlexEvent):void
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, loaderComplete );
loader.load( new URLRequest( "cards.png" ) );
}

/**
* Extract each card in the deck into their own object
* The object includes a label (rank of suit) and a Bitmap image of the card
*/

protected function loaderComplete( event:Event ):void
{
var suitsIdx:Number = 0;
var ranksIdx:Number = 0;
var cardWidth:Number = 79;
var cardHeight:Number = 123;
var a:Array = [];
var img:BitmapData;

var d:BitmapData = Bitmap( loader.content ).bitmapData;

for ( var i:int = 0; i < 52; i++ )
{
img = new BitmapData( cardWidth, cardHeight );
img.copyPixels( d, new Rectangle( ranksIdx * cardWidth, suitsIdx *
cardHeight
, cardWidth, cardHeight ), new Point( 0, 0 ) );
img.draw( img, new Matrix() );
a.push( new Bitmap( img ) );

if ( i == 12 || i == 25 || i == 38 )
{
suitsIdx++;
ranksIdx = 0;
}
else
{
ranksIdx++;
}
}

list.dataProvider = new ArrayCollection(a);
list.selectedIndex = 25;
}

Friday, November 6, 2009

Getting Behind!

Wow I've really fallen off of keeping updates on here. It's been really busy here at 3-GIS over the past six or so months. We're doing a ton of extensions for our base product and continuing to push our Flex applications to do more than nature intended.

One of the cool things we've done in recent months is release a product called Mapper in a joint venture with another company. You can check it out here tucuxisoftware.com just don't ask me to explain the company name.

I think I dropped off the blog updates when I switched over my main development machine to a Mac. I got busy at that point figuring out everything about it and lost track of doing updates.

In the Adobe world this month's user group meeting we talked about Photoshop to Catalyst to Flash Builder. You can find the post about it here. You may have to be a member to see it, let me know if anyone has any issues.

The other hot topic right now is Google Wave! I've been playing around with it for the last couple of weeks. I'm still not sure what the total value of it is going to be. If anyone is reading this and would like an invite just let me know. I have 10 invites open to the first 10 people to comment here!

Monday, March 16, 2009

FlashVars

I'm currently overseeing a project where our main application is being embedded into another web application. As part of this we needed to be able to pass information from an external source into our app, so we turned to Flash Vars. I'm not going to lie, it was a pain in the butt to figure out how to get them to work. I looked at a number of different examples, all of which failed, before I finally found one that steered me in the right direction, and even it had me doing edits in two or three places that were not necessary. In the end it was pretty simple (of course). Just open up your index.template.html for your application. You are going to edit the AC_FL_RunContent, but be careful because it's in two places, one for if the client didn't have the right flash player and one (the second one) for if they did. You need to edit this second one. Mine ended up looking something like this:

AC_FL_RunContent(
"src", "${swf}",
"width", "${width}",
"height", "${height}",
"align", "middle",
"id", "${application}",
"quality", "high",
"bgcolor", "${bgcolor}",
"name", "${application}",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer",
"FlashVars", "MyToken="+token+"&a="+aVariable+"&b="+bVariable+""
);
Then to access the Flash Vars from Flex:

var paramObj:Object = Application.application.parameters;

var mapperToken:String = paramObj.MyToken;
var outsideA:String = paramObj.a;
var outsideB:String = paramObj.b;
And that was it. I of course check to make sure none of them are null etc. so that the application can still work stand alone. All in all it was a ton of ferreting around for the information and easy to do once I found this. Hope it helps someone else out.

Wednesday, January 28, 2009

Flex 3 for Education

Sorry no updates for a while on here. Listening to the Tech Wednesday for the Flex SDK today though they said a couple of things that I thought were worth posting on.

  1. Flex 4 will be delivered in Q4 of 2009 with open beta in the second quarter.
  2. Adobe gives Flex Builder 3 Profesional away to students, faculty, and any employees!
Get that free Flex Builder here!

Friday, December 12, 2008

Adobe + ESRI = LOVE?

Bouncing around the Adobe site this morning I came across a large 'Now developing on Flex' area with the ESRI logo as one of those listed. This article was linked and includes excerpts from an interview with Mansour Raad of the ESRI Flex API team among others. It's an nice to know that Adobe has taken notice of all the interest from the GIS community.

Tuesday, November 25, 2008

Working with data in Flex

This session was led by James Ward. I was somewhat familiar with him having found a couple of interesting posts on his blog in the past about easing functions in Flex. He focused mainly on what you should use to store and move your data under different circumstances. He briefly discussed the Tour de Flex AIR application which everyone in the session was given a copy of on a nice 1gb thumb drive. Tour de Flex shows how to use a myriad of components, both built in Flex components and third party ones. I was of course interested in playing with the mapping APIs included from Google, MapQuest and Yahoo Maps.

Next we talked about different ways to send your data over the wire from the server to the client. James has a great Flex application available online which allows you to test out all of the different options. Of course AMF (Remote Objects) was basically the fastest. It did seem to get beaten by Data Services using Flex Paging though, but that's what you pay for with Blaze DS I suppose. The application is quite nice and allows you to send rows across from a server side database.

He followed that presentation by giving a few other examples that boil down to things to be careful of when dealing with large amounts of data. With XML there is a memory overhead which can become significant with large amounts of data and can cause performance issues.

For AMF (surely nothing is bad about AMF! It's a binary, no parsing required, way to send data!) he said to watch out for circular references and the overhead you accept for the use of binding. Sounds like a no big deal thing to me but maybe Adobe pays him to get people to consider buying Blaze DS?

One last thing he talked about was something I had assumed but never really quantified. He built a quick Flex application which loaded 100,000 objects into an Array and the same objects into an ArrayCollection. It took the Array a mere 100 milliseconds to complete where the ArrayCollection took 1.4 seconds! So if you are dealing with large amounts of data and want your application to be fast, watch out for those ArrayCollections.

Monday, November 24, 2008

Flash Security Model

We all know that security is one of the most important parts of any enterprise solution. That said, it's also dead boring. Deneb Meketa led this session and opened with a line very similar to that so I don't feel bad saying it. Before I get into some of what we went over in this session here is a nice video that overviews the first day and general session.

Now that you're excited let's talk security. In order to make this fairly brief I'm mainly going to just go over the five basic security rules Deneb gave us and if I think of anything for each of them I'll expound.

Rule 1: Use least privilege

When creating your cross domain files etc. never use an allowDomain="*". It may be a bit of a pain to actually enumerate the domains allowed to access your stuff but it's much better than being hacked.

Rule 2: Validate Input

You never know what someone might try to stick into the stream as input so validate it on the client side and on the server side.

Rule 3: Deploy HTTPS Consistently

Don't mix HTTP and HTTPS. All you will do is expose holes in your security.

Rule 4: Prototype Early

I thought this was an interesting rule for the Flash Security Model but as he explained a bit more it made perfect sense. If you don't prototype early there may be something you plan on doing which simply isn't allowed within the Security Model. If you prototype that stuff early and find out it won't work you may be able to find an easy way around it. If you wait until the end it may be a nightmare.

Rule 5: Keep Track of Security Changes

The last thing you want is the CEO walking up to you and saying, "Internet Explorer upgraded my Flash Player and now none of our stuff works. What did you break?" Believe me, I know.