`

ActionScript Class for Global Variables in Flexfle

阅读更多
ActionScript Class for Global Variables in Flex
原文:
http://www.kerkness.ca/?p=4

I’ve been reading several blogs and forums on how to implement global variables in a Flex application. It’s tough to find an effective example of how to do this as most threads/comments are flooded with people crying foul that good programming doesn’t need global variables.

While I agree for the most part I’m used to having some sort of config file in my applications which hold defined constants that are likely to change depending on the deployment or version of the application. Eg: In my php applications I keep database connection information in a config file so that i can easily switch between a development database or production database.

The best solution I’ve found to do this in a Flex Application is to include in the root directory of your Flex application a ActionScript class that contains properties for all the constants or global variables you’ll need to define.

Action Script : Settings.as

package
{
  public class Settings
  {
    static public var SiteUrl:String="http://www.mydomain.com";
  }
}

Example MXML File Using Settings.as

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns="*">
  <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    private function testSettings():void
    {
        Alert.show( Settings.SiteUrl );
    }
    ]]>
  </mx:Script>
  <mx:Button label="test" click="testSettings()"/>
</mx:Application>


Important things to make note of in this example you’ll need xmlns=”*” in the opening tag of any MXML file or component which needs access to the properties of Settings.as. You’ll also need to make sure Settings.as is the root folder of your application.
分享到:
评论

相关推荐

    ActionScript 3.0 for Adobe Flash Professional CS5 Classroom in a Book

    《ActionScript 3.0 for Adobe Flash Professional CS5 Classroom in a Book》是一本官方培训教程,由Adobe Systems出版。本书旨在帮助读者掌握Adobe Flash Professional CS5中ActionScript 3.0的核心编程技术。通过...

    ActionScript for Multiplayer Games and Virtual Worlds01

    ActionScript for Multiplayer Games and Virtual Worlds

    ActionScript for Multiplayer Games and Virtual Worlds.pdf

    《ActionScript for Multiplayer Games and Virtual Worlds》是一本专注于使用ActionScript语言开发多人在线游戏和虚拟世界的书籍。ActionScript是基于ECMAScript的一个由Adobe Systems为Flash平台所发展出的编程...

    ActionScript for Multiplayer Games and Virtual Worlds03

    ActionScript for Multiplayer Games and Virtual Worlds

    actionscript for multiplayer Games and virtual worlds_源码

    《ActionScript for Multiplayer Games and Virtual Worlds》是关于使用ActionScript开发多人在线游戏和虚拟世界的源码集合。这个资源包含了书籍的上半部分,主要涵盖了从基础到进阶的ActionScript编程技术,特别...

    ActionScript Class Diagram

    as3 类关系图 jpg格式,as3 类关系图 jpg格式,as3 类关系图 jpg格式,as3 类关系图 jpg格式,as3 类关系图 jpg格式

    ActionScript 3 For Adobe Flash CS4 Professional

    ActionScript 3是Adobe Flash平台的一种面向对象的脚本语言,主要用于开发Flash和Flex应用程序。随着Flash CS4 Professional的推出,许多设计师和开发者需要从ActionScript 2迁移到ActionScript 3。本指南为设计师和...

    ActionScript for Multiplayer Games and Virtual Worlds05

    ActionScript for Multiplayer Games and Virtual Worlds

    Foundation ActionScript 3 for Flash and Flex August 2009

    《Foundation ActionScript 3 for Flash and Flex》是一本专注于介绍Adobe Flash和Flex平台上的ActionScript 3.0编程语言的书籍。本书由Darren Richardson撰写,并得到了Paul Milbourne的技术审阅支持。作为一本重要...

    Learning ActionScript2.0 in Flash

    1. **基础语法掌握**:首先,熟悉ActionScript 2.0的基本语法和结构,包括变量声明、控制语句(如if...else、switch...case)、循环(for、while)等。 2. **事件驱动编程**:理解如何使用事件来控制应用程序的流程...

    actionscript for multiplayer Games and virtual worlds_源码(下半部)

    《ActionScript for Multiplayer Games and Virtual Worlds》是一本专注于使用ActionScript开发多人在线游戏和虚拟世界的书籍。ActionScript是Adobe Flash平台的主要编程语言,尤其在创建互动内容、游戏和网络应用...

    Creating_ActionScript3_components_in_flash_source

    这篇教程“Creating_ActionScript3_components_in_flash_source”聚焦于如何在Flash源文件(.fla)中创建自定义的AS3组件。通过深入理解这个主题,开发者可以扩展Flash的功能,创建可复用的UI元素,提高代码效率。 ...

    Foundation ActionScript 3.0 with Flash CS3 and Flex.2008.pdf

    《Foundation ActionScript 3.0 with Flash CS3 and Flex》一书由Steve Webster、Todd Yard和Sean McSharry合著,旨在为读者提供一个全面深入理解ActionScript 3.0编程语言及其在Adobe Flash CS3和Adobe Flex环境中...

    Foundation ActionScript 3.0 with Flash CS3 and Flex.pdf

    - **书名**:《Foundation ActionScript 3.0 with Flash CS3 and Flex》 - **作者**:Steve Webster, Todd Yard 和 Sean McSharry - **出版年份**:2008年 - **ISBN**:978-1-59059-815-3(平装版)、978-1-4302-...

    ActionScript语句中文全解

    ActionScript是一种基于ECMAScript规范的编程语言,主要用于Adobe Flash平台,用于创建交互式富媒体内容,如网页动画、游戏和应用程序。随着HTML5的兴起,ActionScript在现代Web开发中的应用已经减少,但仍有大量的...

    ActionScript

    2. **基础语法**:ActionScript的基本语法包括变量声明、数据类型(如Number、String、Boolean等)、流程控制(如if语句、for循环、while循环)、函数定义与调用等。理解这些基础知识是编写ActionScript程序的基础。...

    ActionScript for Multiplayer Games and Virtual Worlds

    在探讨“ActionScript for Multiplayer Games and Virtual Worlds”这一主题时,我们首先需要理解ActionScript是一种强大的编程语言,主要用于创建动态网页、游戏和虚拟世界应用。它最初由Macromedia开发,后被Adobe...

    ActionScript3.0

    and special types Packages Alphabetical entries for class elements An index containing all entries An appendix that compares some key language and API changes from ActionScript 2.0 to ...

    Actionscript中文帮助文档

    1. **基础语法**:ActionScript的基础包括变量声明、数据类型(如Number、String、Boolean、Object等)、运算符、流程控制(if语句、for循环、while循环)以及函数的使用。 2. **面向对象编程**:ActionScript 3.0...

    flex actionscript学习笔记

    - **变量(Variables)**:ActionScript 3.0引入了严格的类型系统,变量必须声明类型,这有助于防止运行时错误,并在编译时进行类型检查。 - **函数(Functions)**:函数在ActionScript 3.0中变得更加规范,支持命名...

Global site tag (gtag.js) - Google Analytics