Flex :: Static Var Or Use FlexGlobals.topLevelApplication?
Jun 22, 2011
In Flex 4, if I have something like user information that I want to be able to access from anywhere in the application, is it better to create a class with static var for the info or to have the variables in the top level application and access via flexGlobals. topLevelApplication?
I am migrating an application from Flex 3 to Flex 4. In some cases there are popup windows of which the width and height is bound to the application width and height.
Suppose I have an application and a global event listener in it. Should the key events, who are fired in the PopUp, be caught by that listener? Or maybe popups are not placed in that hierarchy?Here's simplified test-code for you to understand what I'm talking about:
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"> <mx:Script><![CDATA[ private function init():void {
I am currently trying to use the new approach of using FlexGlobals to access an ArrayCollection that I have on the Default view of a mobile application I am developing. Below is the code that makes up the creation and population of that array on the Default view which happens as soon as the app is initiated:
private var ids:ArrayCollection = new ArrayCollection(); private function loop():void { var index:int;
[Code].....
I could only assume that the ArrayCollection I had created in my default view has no value once I navigate away from it. this as there seems to be next to no documentation on how to do these types of things with FlexGlobals?
I've got a component written for my app by a third party developer and am trying to integrate it, but I've found a bug that seems like it's either a compiler bug, or there's something with how Flex and static variables work that I wasn't aware of.Basically, I have this:
public class ModeChangeController { public static const DISPLAY_MODE:String = "DisplayMode"; }[code]...
If I use //V2 (i.e. comment out V1), a bug occurs at the startup of the application (some TextFields are uneditable and contains no text), but with //V1 and not V2, it works fine. If I comment out both, that also works fine (I don't get the TextField bug).It took me a while to figure out that it was that static const String that was causing the issue, but I'm still not sure why or if there's something I can do about it except for just moving the DISPLAY_MODE to Events (which is what I've done at the moment, but it's not a particularly nice solution).There are no errors in the log. The order of the includes in my BorderContainer code doesn't matter. I've googled for "as3/flex static initialization order" but haven't found anything.
Clarification: showInitialView() never gets called. It doesn't get there before the other bug shows up. Just having the V2 line there causes the problem.
Update: I've fixed my problem with the TextInput strings not showing: Turns out that adding the component caused the Tahoma font to not show up. However, setting the font-weight to bold fixed that problem, or switching to Arial. With that said, the original question still stands, because when I ran it without V2, it found Tahoma with normal font-weight.
1. Static var(an Array) stored in a class. 2. You create a variable reference to the static class in a separate class. 3. Splice some items from the reference variable in the separate class. 4. Trace the static class and the items have been removed from that too. 5. Verify several times. 6. Get confused. 7. Post on Kirupa.
Ok, so I have a bit of a mess here (Which I'm probably not doing right anyway, which could be my problem...). I have a document class, I'll call it as Body.as, that creates an object from another class known as Headgear.as. There are also other objects created from other classes, or will be in the future. Now, amoung all this, Headgear.as and all of the other classes Body.as will use to make objects require the use of dragging functions (starting and stopping dragging). On stopping drags, position checks are then made to compare a particular hidden movieclip with the dragged MC.
To try and save myself some hassle (from making the same functions over and over to ensuring that when the objects are created I don't need to send a complete crapload of variables just to ensure the position checking function would work), I had the functions for the event listeners (Which are set-up on the draggable MCs in Headgear.as) just direct to functions in Body.as
If I created a static method. say I decide to call on other methods within that static method. Do those methods I call on need to be static as well? what If I used some of the properties. Not to store data permanently, but just within that process. Do those properties need to be static ??
Yesterday I found myself wondering, what is the difference between either having a class with methods that are all static, or simply giving your class the static attribute?
Alright, so I have a class that is linked (via the linkage panel) to a scrollbox class. I'll paste the class here:[code]Ignoring the formatting, the commented out functions are the ones causing the issue. Adobe says that it's a static class and I can't use non-static functions. The way I wanted to use it was:
1. Call the page button generating function above.
2. In the main code in my program is this line:scrollbox.setClickFunction(historyContent.generate Page);So when the buttons that are supposed to be generated are clicked, the scrollbox class can call the History pages generatePage function and pass it which page to show. (I did this because there was a lot of text and a limit on how much would display, so small chunks sounded logical).
3. In the onClick function (which I haven't finished yet because the rest wont work), when you click one of the buttons it calls the set function. Its that simple.
testing a Flex app without static Automation IDs attached to components? All of the elements in the apps are generated .....
We've investigated FlexMonkey but it appears to be incompatible with any app that utilizes the ExternalInterface. RIATest's scripting language leaves much to be desired...
I am trying to set some public static constants on a class conditionally by passing variables to the compiler e.g. -define=CONFIG::ENVIRONMENT,'testing_server'
[Code]...
Obviously this means I have to tinker with long command line setting each time. I thought my initial approach was possible given the documentation and various tutorials I have read.
I'm trying to get this code working: <mx:DataGrid x="359" y="221" width="623" height="176"> <mx:dataProvider> <fx:Object name="Garbage Collection" code="7777" hours="2"/> <fx:Object name="Road Repair" code="8888" hours="6"/> <fx:Object name="Lawn Maintenance" code="9999" hours="12"/> [Code] ..... I even don't have the header text in my columns.
While this is similar to another post, that post (does not indicate how to perform this (if it can be done) without instantiating an object. Also, without success I have tried multiple variations on the theme of:
I have used Reflection in both C# and Java. BTW, the code that I am attempting to get to work in Flex is mirrored in both those languages and works as expected.
Non-functioning Flex Code: private function ipMethodTester( ipMethodName:String, shouldPass:Array, shouldFail:Array):void {
I'm working with an application which was originally designed to make heavy use of static-variables and functions to impose singleton-style access to objects. I've been utilizing Parsley to break apart some of the coupling in this project, and I'd like to start chiseling away at the use of static functions. I will explain the basic architecture first, and then I'll ask my questions. Within this application exists a static utility which sends/receives HTTP requests. When a component wishes to request data via HTTP, it invokes a static function in this class: Utility.fetchUrl(url, parameters, successHandler, errorHandler); This function calls another static function in a tracking component which monitors how long requests take, how many are sent, etc. The invocation looks very similar in the utility class:
We are using as3Crypto library in my project. We have downloaded the code, modified a bit and started using it. Initially we have included the complete code as the part of the project. Now we are trying to compile it as Separate Library file(.swc). When we compile the code, we didn't get any errors, but we got one warning saying
[Code]....
When we check the code, we traced it to a code file AESKey.as, especially from a Static initializers code block. I can't simply ignore the warning as it is the critical part of my applications security.
I'm re-writing an MXML item renderer in pure AS. A problem I can't seem to get past is how to have each item renderer react to a change on a static property on the item renderer class. In the MXML version, I have the following binding set up on the itemenderer:instanceProperty=callInstanceFunction(ItemRenderer.staticProperty)What would be the equivalent way of setting this up in AS (using BindingUtils, I assume)?PDATE:So I thought the following wasn't working, but it appears as if Flex is suppressing errors thrown in the instanceFunction, making it appear as if the binding itself is bad. indingUtils.bindSetter(instanceFunction, ItemRenderer, "staticProperty");However, when instanceFunction is called, already initialized variables on the given instance are all null, which was the cause of the errors referenced above.
If all I have is an instance of an object, can I call a static method of its class? For fun, let's say I don't know what the name of the class is, only the name of the static method.
Are there any way to declare a child component in mxml which is private/protected or even static? Sure we can do this inside a script tag, but are there any other way?
Once I get logged in on my login control, I would like to change the selected index of my ViewStack. From my outside controls, I cannot reference my ViewStack by name. I can reference a public static function from an outside control however I cannot refer to the ViewStack from within that function.
I have a class ErrorMessages which holds all my error messages as static constants. So I could access them like ErrorMessages.PASSWORD_INVALID or ErrorMessage.PASSWORD_TOO_SHORT. I want to know if it is possible to have separate classes that hold subset of these constants and access them like ErrorMessages.PASSWORD.INVALID or ErrorMessages.PASSWORD.TOO_SHORT, etc. This way I can more structured static structure and makes it much easier to use autocomplete. I tried few different ways and couldn't figure out if this was possible..
I need to create a static frame and a changing content... currently envisaged as frame containing the side panel and header and footer content.
The content panel will call mxml based on the content sought.
a) how is the frame paradigm- with static frame "containing" other content done. I dont want to repeat the header and footer logic in every 'content section' code?
b) how is the hyperlinking between content sections done- using 'states' seems convoluted
When I set a breakpoint and debug my application, Flash Builder 4 is not displaying static variables within the variables window. I'm using flash builder 4 to execute flex unit tests on one of my AS3 classes. I set a static variable within the [Before] function, which is accessed in each of the tests. I've set a breakpoint within one of the tests to see why it is failing, but I notice that static variables don't appear when I expand the 'this' object within the variables window. (In this case my static variable is the only variable associated with the class, so the only object in the variables window is the "this" object). How to make static variables appear in the variables window?