dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Scope in MXML in Flash Builder 4.5

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349

    Scope in MXML in Flash Builder 4.5

    I've got years of experience with AS3 but am very new to MXML. I've downloaded Flash Builder 4.5 in the hope of building some mobile applications and am stumbling over the integration of Actionscript with MXML. I need to dynamically build an elaborate game interface by drawing shapes.

    For some reason, Flash Builder tells me I have an error in the Actionscript here:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.HelloWorldHomeView">
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
    
        <fx:Script>
            <![CDATA[
    
                var myString:String = ;
                
                // !!! error: 1120: Access of undefined property myString
                myString = ;
                
            ]]>
        </fx:Script>
    </s:ViewNavigatorApplication>
    I don't understand why this would be an error. Additionally, I'm wondering why I cannot refer to the this object in code I enter in this MXML file. The Flash Builder IDE complains in that case that "1042: The this keyword cannot be used in static methods. It can only be used in instance methods, function closures, and global code."

    Given that the Actionscript exists in the very first script in my application's MXML file, I would expect that "this" would refer to my application itself as if I had entered this actionscript on the first frame of my Flash Movie in the Flash IDE. Either that or the actionscript would be global. But static? How is this actionscript static?

    Is there any sort of tutorial that explains the idea of scope and how MXML scripts are scoped, I would certainly appreciate it. I'm also interested in learning how best to organize my actionscript and MXML in my Flex projects.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    There is nothing myString can refer to. At least you need to refer to quotations ("").

    Regarding the "this" issue, "this" is not inside of a function and will give you an error.
    Here is a good explanation for your problem. It is explained in Flash and then you immediately understand why.

    http://blog.anselmbradford.com/2009/...r-errors-1042/


    Regarding the organization of a Flex movie I recommend the use of a Framework. I use the MATE framework, which will result in loose relation between Flex objects and is based on a MVC model.

    http://mate.asfusion.com/

    But any other framework is fine too.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    Thanks for your response.

    Looks like I had a cut-and-paste error. I understand after looking around that any statements put inside such a <script> block will be wrapped in a class block. Thanks for the link on the error description that is a very helpful description of the error.

    Still trying to get my head around the MXML -> AS3 relationship. The -keep-generated-actionscript flag for the compiler is proving quite helpful.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center