Quicksearch |
Saturday, March 15. 20082008 PHP Quebec Conference
The 2008 edition of the conference is almost over (we have yet to go to the sugar shack). The event was a total success. For the first time, all tickets we sold out. We had wonderful sponsors that allowed us to do more than before (elePHPants, job fair, cocktail...) We had very good speakers and quality presentations. I talked to many visitors and they were all very happy with the event. It is always a pleasure for me to organize this event and I will surely start planning next year's edition soon. Thanks to all the volunteers who helped us to keep the conference smooth.
Friday, March 7. 2008Data Binding expressions
In MXML, you may use expressions as a source of data binding.
Example: <mx:Label text="Beer" visible="{age >= 18}" />The Label will only be displayed if the person is 18 or older.Did you try a more complex expression? <mx:Label text="Beer" visible="{age >= 18 && gender == 'male'}" />Ah ha! You get a compiler error. Why? Because you're inside MXML and the & character is special.Solution: replace the & with & <mx:Label text="Beer" visible="{age >= 18 && gender == 'male'}" />
Friday, March 7. 2008[Bindable] public override
I stumbled upon a compiler error when overriding a setter function with the Bindable metadata tag: "overriding a function that is not marked for override"
The answer is short and simple: use --[Bindable] public override-- instead of --[Bindable] override public-- It may sound silly but the override actually has to come second in order for the compiler to interpret it properly in this particular situation. Thursday, March 6. 2008Instantiating and displaying MovieClips from loaded SWF
So you want to dynamically load a .swf, instantiate it and add to to a SWFLoader control.
First, loading the .swf: var loader:Loader = new Loader(); Now, to get its classes, we need to listen for the loading completion: loader.addEventListener(Event.INIT, callbackFunction); Once done, the callbackFunction will get and instantiate a class: var mcClass:Class = Hurray! Now we can add it to some appropriate container: someSwfLoader.addChild(mc); Now we want to scale it to fit the available space: mc.scaleX = mc.scaleY = someSwfLoader.width / mc.width;(a more complex algorithm may be used) A problem may arise if your clip content is not at 0,0 coordinates: var bounds:Rectangle = mc.getBounds(Application.application.stage);(if you have an ActionScript project instead of Flex, you'll need to access the stage by other means) Thursday, February 28. 2008AS3 data binding and component states
If you ever developed a complex data-driven application, you probably stumbled upon the data binding nightmare. Altough a great feature in Flex (a central one in my opinion), it lacks a bit of control.
I needed a form with multiple states depending on the flavor of the edited object. This way, I could have common fields to all object types and add a couple of fields based on the object type. However, these fields' values were bound to properties of the edited object. When selecting an object from the list, the fields should update themselves. Bindings are executed to set field values. Now, since I use form states, all fields are technically on the stage and all bindings will execute, regardless of the type of the selected object. Basic example I have a form to edit animal properties (number of legs, head size, etc.) I have some extra fields depending on the animal type (mammals have fur length and density, birds have wing span, etc.) Every animal type has an associated state: <mx:Form> The animal variable is set when an element is selected from a list. It can be an instance of a custom class Mammal or Bird which extends the Animal class. The state also changes according to the type selected. The problem occurs when I select a non-Mammal. The binding will execute, expecting a Mammal for the TextInput's text property. An error will be thrown saying that Bird (or other) could not convert to Mammal. This is to be expected, as the TextInput in question remains on the stage even if the state is invisible. What's the solution? Perhaps not the most neat, but it works: create extra variables for every type. Now you will have animal:Animal, mammal:Mammal and bird:Bird variables with their respective types. When an animal is selected, every type except the needed one is set to null. The animal variable still points to the selected animal. The MXML changes: <mx:TextInput text="{mammal.furLength}"/>What happens? When the bindings execute, if a Mammal is selected, the mammal variable is equal to a Mammal instance and everything is smooth. If a Bird is selected, the mammal variable is null and everything is smooth again. Hurray! It took me about 2 hours to figure out. If you have a better solution, please share. |
CategoriesSyndicate This BlogBlog Administration |
Powered by s9y - Design by Anna Filina