How to link a .mxml file and a .as file ?

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default How to link a .mxml file and a .as file ?

    Hello,

    I don't like so much the idea about mixing action Script ( processing code )
    and form description ( end user presentation) even if the tags make it proper
    .... it looks that FLEX is based on taht principle and I probably need to be
    used to that.

    In the meantime I've looked to some ways to 'link' a formular made of a .mxml
    file and a class nested in an action script file (.as file in a particular
    directory, for example) But I've not found any of them.
    The className is a read-only property and the compiler options look to make
    the things a litlle beat difficult.

    Do you know if that can be done ?
    Thank you in advance

    bendev Guest

  2. Similar Questions and Discussions

    1. How to see the .AS file that .MXML file is translated tobefore being compiled to SWF?
      I am trying to dynamically load some other Applications in one Application, use ActionScript but not SWFLoader tag, it looks like: ...
    2. How to get swf file of any mxml file in flex1.5
      hi all, can anybody tell i have one mxml file now when i run this i file server generate swf file dynemically ....now my requirement is i...
    3. how to load external html file into mxml file
      hi all plz tell me how i can load external html file in mcml file just like say when we receive mail in inbox and see our mail data .. i have...
    4. Can I embed external MXML in another MXML file?
      Hi - I'm new to this so please bear with me. I'm trying to do something like you do in JSP's with a JSP include where I can import prewritten code...
    5. Help needed with ASP form browse for file, create link to file and insert in access database
      I have a form where a user enters their name, date etc. i also want them to be able to click on a browse button and select a file which will then...
  3. #2

    Default Re: How to link a .mxml file and a .as file ?

    The best way is to put your as code into its own .as class.

    You then instantiate that class in mxml, giving it an id, for example, id="fn".

    You reference properties(variables and getter setter functions) and
    methods(functions) lke this:
    var myVar:String = fn.my/var;
    var myFuncResult:String = fn.myfunc(myVar); //or whatever

    This architecture has the benefit of helping to avoid the 32k limit, as well.

    Let me know if you need more examples.

    Tracy

    ntsiii Guest

  4. #3

    Default Re: How to link a .mxml file and a .as file ?

    In fact here is an example. It has three files. A test file that uses both
    class files, an ordinary class file that is instantiated in an mxml tag in the
    test file, and a static class whose functionality is used without an instance.

    Tracy



    UtilityClassTest.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*">
    <mx:Script><![CDATA[
    import UtilityClassStatic
    public var sAppProperty:String = "BAZ";
    ]]></mx:Script>
    <UtilityClass id="u" app="{this}"/>
    <mx:Label text="{u.getFoo()}" />
    <mx:Label text="{UtilityClassStatic.getBar()}" />
    </mx:Application>

    UtilityClass.as
    // Example utility function class for dynamic instantiation
    class UtilityClass
    {
    public var app:UtilityClassTest;
    public function getFoo():String{
    return "FOO" + app.sAppProperty;
    }
    }//UtilityClass

    UtilityClassStatic.as
    // Example utility function class for Static reference
    class UtilityClassStatic
    {
    public static function getBar():String{
    return "BAR";
    }
    }//UtilityClassStatic

    ntsiii Guest

  5. #4

    Default Re: How to link a .mxml file and a .as file ?

    Hello,

    Thank you ... That's really what I was looking for.

    I just add a little comment : if you describe the namespace of the package
    where you actionScript file is :
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
    xmlns:myNameSpace="myDir.*">

    then you will instance the class with :
    <myNameSpace:myClass id="u" app="{this}"/>

    Oh myDir !
    Bye for now


    bendev Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139