FlexPrintJob and Firefox = BLANK + BLANK -> Flex, you [still] suck part 2
Filed under Lab Work, Programming | Tags:Actionscript 3,Flex
This Friday, at 5 pm, i was told that a print job class for a project in which we were supposed to be done, was not working. Nothing like getting that news before the weekend. Going into my code, i thought, i am sure it’s a quick fix. The main issue was Firefox would draw a blank both on screen and in the expecte print page. Doh, double whammy.
The class itself was not the issue… i am going to document that class at the end of this post cause i will likely use it again. Anyway, i spent the next 5 hours banging my head against the wall, reading about crazy hacks that could fight firefox, and wondering if my weekend just went to hell. In the back of my head, was one of my peers who is a strong believer in ‘rest = fresh minds’– so, against my will, i went to bed.
Next day: i decided to recreate the issue on a blank flex project, still using my questionable class. AND HERE WAS THE DISCOVERY. My original approach was this:
This Friday, at 5 pm, i was told that a print job class for a project in which we were supposed to be done, was not working. Nothing like getting that news before the weekend. Going into my code, i thought, i am sure it’s a quick fix. The main issue was Firefox would draw a blank both on screen and in the expecte print page. Doh, double whammy.
The class itself was not the issue… i am going to document that class at the end of this post cause i will likely use it again. Anyway, i spent the next 5 hours banging my head against the wall, reading about crazy hacks that could fight firefox, and wondering if my weekend just went to hell. In the back of my head, was one of my peers who is a strong believer in ‘rest = fresh minds’– so, against my will, i went to bed.
Next day: i decided to recreate the issue on a blank flex project, still using my questionable class. AND HERE WAS THE DISCOVERY. My original approach was this:
import com.loomisgroup.CiscoPrintJob; import mx.controls.Button; import mx.controls.Image; private var i:Image private var pj:FlexPrintJob private var ar:Array private function init():void { ar=new Array() var re:URLRequest= new URLRequest() re.url='0.jpg'; i= new Image() i.source='0.jpg' i.addEventListener(Event.ADDED_TO_STAGE,done) ar.push(i) addChild(i) } private function done(e:Event):void { printit() } private function printit():void { var b:Button= new Button() b.label='print' b.addEventListener(MouseEvent.CLICK,confirm) b.y=300 addChild(b) } private function confirm(e:MouseEvent):void { new CiscoPrintJob(ar) } } private function done(e:Event):void { var tm:Timer= new Timer(1000,1) tm.addEventListener(TimerEvent.TIMER,waitforit) tm.start() } private function waitforit(e:TimerEvent):void { new CrappyFlexPrintJob(ar) }
As the smart ones out there will conclude immediately is that DESPITE the ADDED_TO_STAGE handler, confirming that my Image component was indeed available, Flex just wants more time to do the job…enter the lovely timer- yes, a simple 1 second delay. I can careless about people on dialup [PODUP], and frankly, PODUPs won’t sit through the preloader on this project. So…the above turns into this:
import com.ericmcconkiegroup.CrappyFlexPrintJob; import mx.controls.Button; import mx.controls.Image private var i:Image; private var pj:FlexPrintJob private var ar:Array; private function init():void { ar=new Array() var b:Button= new Button() b.label='print' b.addEventListener(MouseEvent.CLICK,confirm) b.y=10 addChild(b); } private function confirm(e:MouseEvent):void { i= new Image() i.y=50 i.source='0.jpg' i.addEventListener(Event.ADDED_TO_STAGE,done) ar.push(i) addChild(i) } private function done(e:Event):void { var tm:Timer= new Timer(1000,1) tm.addEventListener(TimerEvent.TIMER,waitforit) tm.start() } private function waitforit(e:TimerEvent):void { new CrappyFlexPrintJob(ar) }
Of course, the code for this post is the VERY simplified version of what we were trying to accomplish. In the end, the goal was to get Firefox to a)print and b) not draw a blank browser. NOTE: while both were accomplished, FF still insists on drawing a blank screen while the user confirms the print job request from the operating system. In the end, i’ll take that.
Yes Flex, you suck, and your big brother (yeah, i am talking about Flash, the shadow of whom which you will always be under) is still my preference.
oh yeah, the class- to keep things short, for those who are done i’ll post it separate.
CrappyFlexPrintJob.as
Filed under Lab Work, Programming | Tags:Actionscript 3,Class,Flex
The prinjob class [very straight forward]- it was more to keep out clutter code:
package com.ericmcconkie { import flash.events.EventDispatcher; import mx.printing.FlexPrintJob; import mx.printing.FlexPrintJobScaleType;</code> <code>public class CrappyFlexPrintJob extends EventDispatcher { private var que:Array; public function CrappyFlexPrintJob(printJobQue:Array) { super(); que=printJobQue; var printJob:FlexPrintJob= new FlexPrintJob() // Start the print job. if (printJob.start() != true) return; printJob.printAsBitmap=true // Add the object to print. Do not scale it. for(var b:int=0;b { printJob.addObject(que[b], FlexPrintJobScaleType.SHOW_ALL); } // Send the job to the printer. printJob.send(); //dispatch event that we are ready to clean up or move on dispatchEvent(new CrappyFlexPrintJobEvent(CrappyFlexPrintJobEvent.DONE,0)) } } }
And it’s cousin – The Event subclass:
package com.ericmcconkiegroup { import flash.events.Event; public class CrappyFlexPrintJobEvent extends Event { public static const PRINT_PAGES:String='printPages'; public var pageNum:Number; public function CrappyFlexPrintJobEvent(type:String,_num:Number, bubbles:Boolean=false, cancelable:Boolean=false) { super(type, bubbles, cancelable); pageNum=_num; } public override function clone():Event { return new CrappyFlexPrintJobEvent(type,pageNum,bubbles,cancelable) } } }
Cisco Page-flip Catalog
Filed under LoomisGroup, Programming, Projects | Tags:Actionscript 3,Flex,PHP

A dynamic Flex online catalog with a page turn effect .