Sticky scroll bar - Flex bug
by Patrick on Jun.23, 2009, under Code == Life
So I was made a datagrid and I dropped in a canvas, then I ran into this annoying documented bug with the Flex Framework, apparently the mouse up event is lost by Flashplayer sometimes, causing the scrollbar to be sticky, it remains up when you mouse away from the scrollbar, it probably has something to do with some memory issues with Flash and the browser some where…
So thanks to Pixelbreaker’s mac scroll wheel class, by looking at his ingenious solution to make the scroll work on the mouse in Firefox, I made a simple solution to solve this problem too.
Simple to get started, this goes at the top of your SWFObject template (you should be using swfObject, find the template here)
1 | <script type="text/javascript" src="js/mouseupfixer.js"/> |
This goes underneath your embedSWF statement:
1 | swfmouseup.registerObject(attributes.id); |
Then include this actionscript file, When you have access to the stage, after an applicationComplete event in Flex, pass in a reference like this:
1 | MouseUpFixer.setup( application.stage); |
Download the here.
Sending dates back and forth to your server with php in AMF
by Patrick on Mar.05, 2009, under Code == Life
Since I spend a lot more time in Flex, coding Actionscript than I do spend time coding php, I had to scratch my head a bit and remember how to exchange dates from Flex to the database with the zendAMF remoting framework. So, I think this is a good demonstration of some code that can help. Of course, you need to convert your Actionscript date object into milliseconds first. I am sure you know how to do that, if not look at getTime(). Secondly, pass your time amounts to the server and then divide that amount by 1000 on the server side because php uses seconds with it’s date object, not milliseconds like Actionscript. Then there’s the FROM_UNIX_TIME mySQL method you’ll need to wrap around these php date objects. Since you are using the timestamp db field for your dates, I hope. That’s really it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | class GetAdmin { function getGamesPlayed($start,$end) { $handle = mysql_connect("localhost","root",""); mysql_select_db("db",$handle) or die("Database Not Found"); $mysqldate1 = date( 'Y-m-d H:i:s', $start/1000); $phpdate1 = strtotime( $mysqldate1 ); $mysqldate2 = date( 'Y-m-d H:i:s', $end/1000); $phpdate2 = strtotime( $mysqldate2 ); $query="SELECT count(*) " . "FROM `gamesplayed` WHERE timestamp >= " . "FROM_UNIXTIME($phpdate1) " . "AND timestamp < FROM_UNIXTIME($phpdate2)"; $result = mysql_query($query,$handle) or die("Failed Query"); return $result; } function getTotalGamesPlayed($start,$end) { $handle = mysql_connect("localhost","root",""); mysql_select_db("db1",$handle) or die("Database Not Found"); $mysqldate1 = date( 'Y-m-d H:i:s', $start/1000); $phpdate1 = strtotime( $mysqldate1 ); $mysqldate2 = date( 'Y-m-d H:i:s', $end/1000); $phpdate2 = strtotime( $mysqldate2 ); $query="SELECT count(*) " . "FROM `answers` " . "WHERE created >= " . "FROM_UNIXTIME($phpdate1) " . "AND created < FROM_UNIXTIME($phpdate2)"; $result = mysql_query($query,$handle) or die("Failed Query"); return $result; } function getTotalAnswers() { $handle = mysql_connect("localhost","root",""); mysql_select_db("vo5_ufc",$handle) or die("Database Not Found"); $mysqldate1 = date( 'Y-m-d H:i:s', $start/1000); $phpdate1 = strtotime( $mysqldate1 ); $mysqldate2 = date( 'Y-m-d H:i:s', $end/1000); $phpdate2 = strtotime( $mysqldate2 ); $query="SELECT count(*) FROM `answers`"; $result = mysql_query($query,$handle) or die("Failed Query"); return $result; } } |
If you need some information about how to set up AMF remoting, this is a fantastic tutorial on how Zend works with AMF by gotoAndLearn. I love these tutorials. - HTH Patrick
MapImage UIComponent
by Patrick on Jan.01, 2009, under Code == Life
A buddy at work, Dan Lacy, uses a pretty cool way of slicing up an image into a CSS sprite grid. It saves download time: see it here. He basically uses an image source with position coordinates to display a small section of an image as a sprite. This works great for logos or other interface elements where you might have multiple sizes on one image like the pink grenade example.
Since we’re working on the same project at arc90, he’s doing a web HTML version in CSS and Javascript, and I am doing an Adobe Air version of the same application. I wanted to take advantage of his work of slicing up images and save time by using his code :). If the images need to be changed, all he has to to is give me the new image with the coordinates, then I can change my Flex CSS file and make an update with in a snap. I wrote this small UIComponent MapImage for Flex that does the same thing in Flex.
Here’s an example of how it works, just give the CSS position and view source parameter and it will do all the rest.
Here’s an example of the CSS:
1 2 3 4 5 6 | .logo { width: 50; height: 50; background-position: 0, 0; /*these values are negative, think of positioning a piece of paper beneath a camera*/ view : Embed(source="../assets/logo_grid.png"); |
To change the image, just use bind the style name property.
Here’s the mxml code example:
The actionscript:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | package com.arc90.display { import com.arc90.rallypoint.settings.*; import com.arc90.rallypoint.utils.*; import com.arc90.utils.*; import flash.display.*; import flash.geom.*; import mx.core.UIComponent; import mx.events.*; public class MapImage extends UIComponent { private var scaleBitmapBoolean:Boolean = false; private var bitmapContainer:Bitmap; private var boundsRect:Rectangle; private var styleNameChanged:Boolean = false; override public function set styleName(value:Object):void { if (value==styleName) return; super.styleName = value; styleNameChanged = true; this.invalidateProperties(); } override protected function commitProperties():void { super.commitProperties(); if (styleNameChanged) { styleNameChanged = false; if (this.getStyle("width")) width = this.getStyle("width"); if (this.getStyle("height")) height = this.getStyle("height"); var offsets:Array = this.getStyle("backgroundPosition"); if (this.getStyle("height")) var view:Object = this.getStyle("view"); if (!view) return; if(view is DisplayObject) { } else if(view is Class) { view = new view(); } if (offsets[0]) var offsetX:Number = parseInt(offsets[0]); if (offsets[1]) var offsetY:Number = parseInt(offsets[1]); if (bitmapContainer) removeChild(bitmapContainer); bitmapContainer = getBitmapDataFromMapCoords(view as Bitmap,offsetX,offsetY,width,height); if (bitmapContainer && this.contains(bitmapContainer)) { } else { addChild(bitmapContainer); } } } private function getBitmapDataFromMapCoords(map:Bitmap,x:Number=0,y:Number=0,width:Number=100,height:Number=100):Bitmap { var b1:BitmapData = map.bitmapData; var b2:BitmapData; var r:Rectangle = new Rectangle(0, 0, width, height); b2 = new BitmapData(width,height,true,0x00000000); var matrix:Matrix = new Matrix(); matrix.tx = x; matrix.ty = y; b2.draw(b1,matrix, null, null, r); bitmapContainer = new Bitmap(b2); return bitmapContainer; } } } |
I didn’t add scaling yet, but I plan to soon.
Fly the Virgin Skies To Adobe Max-SF
by Patrick on Dec.26, 2008, under Code == Life
So, I am on the plane, flying my favorite airline, Virgin America, complete with computers in every seat and disco-lighting. The only thing missing on this hi-tech jet is a mural of the Virgin twins from the old Virgin Records logo, which would be a great addition.
I’m on my way back to my hometown, San Francisco. Finally the flight is relaxing, the screaming 4 year old who has been belting a barrage of ear piercing screams has subsided and I’ve woken up from a little nap. I am now looking out over a fly-over state, probably Nebraska and I am thinking about what lies ahead, the mother of all conferences, “Adobe Max”.Adobe Max promises to be a killer conference, albeit, if you are a fan of Adobe products, and admittedly, I’ve drunk the Kool-Aid. I spend my days working in Flex, about all day, every day that I code. So, for me the the front runners of the sessions that I plan to attend are related to Flex or Air. I have a load of questions about where Flex is headed, so I posted my schedule here so you can see what I am going to be doing.
This schedule for me is not really set in stone, more of a guideline of stuff that looks interesting or related to the project I am working on at arc90. If a session is too crowded or looks like it’s going pointed to the beginner then I’ll roam. The list of stuff going on was long, so much of it looked really interesting and the problem with putting my schedule together was schedule conflict after conflict. When I tried to pick every thing that I had interest in seeing I kind of felt like I was picking a college class schedule at the last minute… Sigh! there’s just no way to see everything. Uh, oh! The boy has started with his tantrum again!1 2 3 4 | public function gagChild():HappyFlyer // Ha! If only... { return peace; } |
As I get time, I’ll post pics and videos, not sure exactly when though.
