Tag: actionscript
Flex Tip: Accessing your AS functions/properties from imported classes
by admin on May.25, 2009, under Development, Flex
Every once in a while you might run across a case where you need to access a property or method from the parent application, and you don’t have the ability to pass the value you need to the class. Or, for example, you’re debugging and you don’t want to write a bunch of code that you’ll have to remove later just to test the value of a variable.
So, with that said the process is fairly simple. The following is a hypothetical example of a class you have imported into your application:
package com.example.scope { private var myVar:String = 'This is NOT the value we're trying to get'; public class scopeExample { public function scopeExample() { import mx.core.Application; // make "Application" available in the current scope trace(Application.application.myVar); // outputs the value of myVar in the main application } } }
You could also use:
trace(parentDocument.myVar); // if the component is a child of the main application
I ran across a post on Holly Schinsky’s blog the other day that had good descriptions of the various scope keywords, and a few tips. All of which is good knowledge to possess, so check it out.
Flex Tips: Keyboard Codes
by admin on Mar.10, 2009, under Development, Flex
If you ever have the urge to capture a specific key pressed in Flex or AS3 in general, there is an excellent list of the keycodes, and costants you can use to represent them in your code here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/Keyboard.html

You can use them statically(without instantiating an object) like so:
trace(Keyboard.TAB); // 9
Flex: getType() schmettype
by admin on Mar.07, 2009, under Development, Flex
I’ve started dabbling in Flex recently, and something that was apparent(and annoying at times) to meĀ early on was it’s strongly-typed nature. Not type as in a keyboard, but variable types. Flex cares very much whether your variable is an Array, or ArrayCollection as it’s knowledge of types is key to it’s processing. This is quite the converse to a language like PHP, which is loosely-typed to say the least.
Anyway, I came upon a case where I needed to know the type a variable was so I could cast it properly(and for debugging), and I found that Flex doesn’t have a function to simply return a variable’s type. There is describeType(), but this returns an XML object with all of the information about the variable — not just the type. Plus you have to import the proper class to use it. So, I threw together this function quickly that will perform the import, and return/alert the type as needed:
I hope someone else can find it useful.