When debugging some container sizes (namely, HBox) in Flex (v. 3.5), I noticed a variable "$height" in the Variables list.
Does anyone know what this variable is? It's marked as protected, but I don't believe I can access it in a child class.
I've noticed it sometimes gets a different value than "height" and "_height". Does anyone know why this is and what it means for how a component is drawn?
The full mx framework source is available in your sdk directory here:
\..\sdks\3.3.0\frameworks\projects\framework\src
The private documentation says.
/*
* This property allows access to the Player's native implementation
* of the 'height' property, which can be useful since components
* can override 'height' and thereby hide the native implementation.
* Note that this "base property" is final and cannot be overridden,
* so you can count on it to reflect what is happening at the player level.
*/
It's marked with mx_internal so you need to declare use namespace mx_internal; to get access to it in your own class.
Flex overrides a lot of methods in it's custom objects, such as FlexSprite.
In their internal code base, they often declare new methods that are marked 'final' and super() to the default method implementation. These final methods start with '$' so that they are easily identifiable.
Another example you would see is '$addChild', flex has custom addChild functionality, but uses the original implementation internally through the '$addChild' method.
Related
I'm working on an active record-like system for symfony and I encountered a problem.
I have a helper class in symfony that is not a service, nor do I want it to become one. This class has a static property named container and a static method to set it. Now the question is, when do I call this static method to set the container?
I've tried the bundle extension, compiler pass, all to no success. (Mostly because they have to be services and when I make it a service and extend it later, it skips the compiler pass.)
Let me know if anyone requires any further information and thanks in advance!
If you want to inject the container into the helper, i.e. call Helper::set($ontainer) you have to do it when the compiled container is available. Both Extension and Compiler Pass modify the container before compilation and therefore are probably not the right place, unless you want to inject the helper as a service into the container and reference the container, much like the following approach outlines.
You could call the Setter-method in your Kernel, where the container is created, or inside a Controller, which is loaded when the container is built and - when you extend the Controller-base class, has access to the container. I don't think that's a good idea though because you can never be certain when/if the method was called and what container is in there. Also, when using the new AbstractController base class you don't have access to the full container, only a service locator for the specific services needed by the controller.
When configuring it as a service inside your services.yaml you can use calls or setter injection to inject the container service by referencing #container. I also wouldn't recommend this, but I consider it the lesser of the two evils, considering what you are asking.
I've got a model class with custom change events, which is working fine if I make a reference to that class in my mxml using;
[Bindable] private var firstClass:FirstClass;
The objects gets filled by a server side script, so don't worry, firstClass isn't null.
Anyhow, accessing firstClasses properties in mxml works perfectly fine using curly brackets. The binding works just as expected.
However, is there any way to access firstClasses properties and set them to say a label with pure Actionscript.
lblTest.text = firstClass.property;
The code above doesn't work. I suppose because it sets a fixed value to the label.
I'm aware of using BindingUtils.bindProperty to explicitly set the source and destination for the binding. However, this turned out to cause huge performance issues in my (mobile) application.
So is there a simpler, more efficient way to do this?
No. The BindingUtils uses propertyChanged events to detects when an object's property changes. You won't be able to bind something without listening to events, and the most painless way to do it is using BindingUtils.
I want to extend or copy the PopUpManager class to add the ability to keep track of the number of windows.
I just want to add a simple windowCount++ when a window is added and windoCount-- when it's removed.
the problem is PopUpManager is a Singleton class... I wasn't able to make it work properly by extending it. And now I have tried to copy the code from the PopUpManager.as file and just add my variable to the end of its functions. It doesn't seem to be working though since it says my properties are undefined even though they are declared above the constructor.
I am thinking I would have to make a copy of the PopUpManagerImpl.as since that's wehre it seems much of the business resides (PopUpManagerImpl extends EventDispatcher implements IPopUpManager) would that allow me to have access to the variable? and should I ignore the manager and just put it in the implementation class?
here is a link about Using the Flex Singleton register, which helped me out when finding myself in the same situation.
I hope you can inspire from that too.
You likely didn't declare yours properties as static. The PopUpManager uses all static methods - this is why working with it you use syntax like:
PopUpManager.createPopUp(...
instead of
var popUpManager:PopUpManager = new PopUpManager();
popUpManager.createPopUp(...
This means that any variables declared in the PopUpManager need to also be static so as to be accessible at the class level.
public static var windowCount:int
Is there a way to change private static field of an alien class?
For example:
package mx.managers {
public class TooltipManager ... {
private static var _impl:IToolTipManager2; // <- assign my own value here
...
}
}
In Java it is possible to do it using Reflection API. What about Flex?
No, that is not possible.
If you are looking into changing the implementation of the TooltipManager, have a look at the Singleton class in the Flex SDK. You'll need to create a custom implementation and register it via the Singleton class before the application initializes. The best is to override the application preloader and do the registration there.
Well, if you feel like you can handle the extra responsibility, you can monkey patch the class by copying the source into your own source tree with the same package and apply the necessary modifications. That way the flex compiler will use your implementation rather than the SDK implementation.
This technique is sometimes used as a last resort to fix issues which cannot be fixed otherwise. Drawbacks include issues such as forwards compatibility and unintended side effects in the same or other classes dependant on the class your editing.
Does anyone know if it is possible to inject into a regular as3 (non mxml) class? I've tried with limited success.
Thanks
Could you be more specific? There's no difference between an "MXML" class and a class defined in ActionScript, it's just different ways of writing the same thing.
All that is needed for injection to work is a source property that is bindable and a destination property that is public (either a public setter or a public instance variable). If those two requirements are met and the code compiles it should work.
Look at the code for the example application you can find here: http://code.google.com/p/mate-examples/wiki/DocumentBasedExampleIntro and you will find a ton of injectors that target classes not defined using MXML (look for injectors targeting classes whose names end in "Model" especially). You can also find countless examples in the Mate forums.