Monday, June 29, 2009

Using Global Variable in Flex

 

1. Declare the global variable in the main .mxml file.

 

In the main .mxml file :

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="TryAS()">
    <mx:Script>
        <![CDATA[
            public var bookSize:Rectangle = new Rectangle(0,0,800,600);

            public function TryAS():void{
                trace("Hello World");
            }
       ]]>
    </mx:Script>
</mx:WindowedApplication>

2.Use Application.application.yourGlobalVariableName to access the variable.

 

In the .as class you write :

import mx.core.Application;

// Application.application.yourGlobalVariableName

Application.application.bookSize.width

No comments: