Flex Certification » Flex Certification, Flex Questions » Action Script
Action Script
How do you use Action Script inside MXML?
•Use ActionScript to define event listeners inside MXML event attributes.
•Add script blocks using the <mx:Script> tag.
•Include external ActionScript files.
•Import ActionScript classes.
•Create ActionScript components.
The Flex compiler transforms the main MXML file and other files it includes into a single ActionScript class.
What is the equivalent ActionScript code for " MyButton.mxml which starts with <mx:Button>"?
class MyButton extends Button
What is the equivalent ActionScript code for " MyApp.mxml which starts with <mx:Application>"?
class MyApp extends Application
What is the equivalent ActionScript code for "<mx:Button id="myButton" click="foo = 1; doSomething()">"?
private function __myButton_click(event:MouseEvent):void {
foo = 1;
doSomething()
}
What is the equivalent ActionScript code for " <mx:Button label="Click Me"
click="textarea1.text=’Hello World’;"
/>"?
public function __myButton_click(event:MouseEvent):void {
textarea1.text=’Hello World’;
}
How to see the generated ActionScript code of MXML?
To see the generated code, set the value of the keep-generated-actionscript compiler option to true. The
compiler then stores the *.as helper file in the /generated directory, which is a subdirectory of the location of the
SWF file.
Can you define new
classes or interfaces in <mx:Script> blocks?
No, you cannot define new
classes or interfaces in <mx:Script> blocks.
Which statements can be outside the functions in <mx:Script> block?
•import
•var
ADOBE FLEX 3 41
Adobe Flex 3 Developer Guide
•include
•const
•namespace
•use namespace
Why should we wrap the contents of <mx:Script> block in a CDATA construct?
This prevents the
compiler from interpreting the contents of the script block as XML, and allows the ActionScript to be properly
generated. Adobe recommends that you write all your <mx:Script> open and close tags as the following example
shows:
<mx:Script>
<![CDATA[
...
]]>
</mx:Script>
Flex does not parse text in a CDATA construct, which means that you can use XML-parsed characters such as
angle brackets (< and >) and ampersand (&).
The Id’s for all the tags generate public or public variables?
The IDs for all tags in an MXML component, no matter how deeply nested they are, generate public variables of
the component being defined. As a result, all id properties must be unique within a document. This also means
that if you specified an ID for a component instance, you can access that component from anywhere in the application:
from functions, external class files, imported ActionScript files, or inline scripts.
How can we refer to a flex component if it does not have an Id property?
By using methods of the component’s
container, such as the getChildAt() and getChildByName() methods.
How can we refer to the current enclosing document or current object?
By using the this keyword.
To access an object
on the application, you use the this keyword, followed by square brackets, with the String inside the square
brackets.
this["myButton1"]
How do we invoke a method from a child document (such as a custom MXML component)?
Using parentApplication, parentDocument, or Application.application properties
How do you create visual flex components in ActionScript?
1. Create using the new operator.
2. Set default properties using standard assignment statements.
3.Use addChild() or addChildAt() to add the new component to a container.
eg: button2 = new Button();
button2.label = "Click Me";
hb1.addChild(button2);
Which is the efficient way ?
1. calling setChildIndex() method after the
call to the addChild() method
2. using the addChildAt()
2. is more efficient.
What are the methods for removing a control?
removeChild(), removeChildAt(), removeAllChildren()
Does calling these methods "removeChild(), removeChildAt(), removeAllChildren()" actually delete the objects?
Calling these methods
does not actually delete the objects. If you do not have any other references to the child, Flash Player includes it
in garbage collection at some future point. But if you stored a reference to that child on some object, the child is
not removed from memory.
Which component you can pass to the addChild?
UIComponent
Which methods are used for creating component programmatically rather than declaratively?
createComponentFromDescriptor() and createComponentsFromDescriptors() methods.
You can set the creationPolicy
property of the component’s container to none to defer the creation of the controls inside that container.
How do you add a Sprite object to Panel container?
Since sprite object that is not a subclass of mx.core.UIComponent, you must wrap it in a UIComponent before you can
attach it to a container
var c:UIComponent = new UIComponent();
c.addChild(spriteObject);
panel1.addChild(c);
Flex includes an Application.application property that you can use to access the root application. You can
also use the parentDocument property to access the next level up in the document chain of a Flex application, or
the parentApplication property to access the next level up in the application chain when one Application object
uses a SWFLoader component to load another Application object.
What is the difference between impirt & include?
There is a distinct difference between including and importing code in ActionScript. Including copies lines of code
from one file into another, as if they had been pasted at the position of the include statement. Importing adds a
reference to a class file or package so that you can access objects and properties defined by external classes.
Can you define classes in the included files?
You cannot define classes in included files, because the MXML file itself is a class.
What are the ways of including the action script in MXML file?
•The source attribute of the <mx:Script> tag. This is the preferred method for including external ActionScript class files.
•The include statement inside <mx:Script> blocks.
<mx:Script source="includes/IncludedFile.as"/>
<mx:Script><![CDATA[
/* The myfunctions.as file defines two methods that
return Strings. */
include "includes/myfunctions.as";
]]></mx:Script>
Is the following code allowed?
if (expr)
include "foo.as";
NO, the correct code is
if (expr) {
include "foo.as"; // All statements inside { } are guarded by IF.
}
Is using a wildcard while importing packages inefficient?
No,Importing an entire package with a wildcard does not create an unnecessarily large SWF file.
What are the types of Custom Components?
User-interface components
Nonvisual components
What are the ways of introspection in ActionScript?
•Using for..in loops
•Using mx.utils.ObjectUtil.toString()
•Using the introspection API
Does describeType(this) Returns information about all the members of the class?
No, the
method returns information only about nonstatic members of the class.
How can you get the information about static members of a class?
describeType(getDefinitionByName("MyClass"))
How can we get the class information ?
ObjectUtil.getClassInfo()
Filed under: Flex Certification, Flex Questions · Tags: Action Script, Flex Certification, Flex Questions







