Included AS file cant access MXML varriables?

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

  1. #1

    Default Included AS file cant access MXML varriables?

    I must be missing something here, but when I add in an Action Script file using
    the <script source="xxx.as"/> or include "xxx.as"; methods the AS file cant
    access variables I declare in the MXML file. Any ideas as to what I'm doing
    wrong?

    jfizer 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. 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...
    3. how do you access an array in an included/required field?
      I have a large array that would be messy to include in the file "main.php" itself and would prefer to include/require it. Say I have the following...
    4. Problem occurs when included file includes anther file.
      The directory structure is as follows: / |-- demo.php |-- inc/ |-- inc1.php |-- inc2.php === file demo.php == <?php require 'inc/inc1.php';
    5. [PHP] Problem occurs when included file includes anther file.
      Thank you for your reply first. Yes I know I could set include_path either in the php.ini or at runtime.But it's a little bit dirty I think.What...
  3. #2

    Default Re: Included AS file cant access MXML varriables?

    I don't answers just what happend with me. In one mxml the same include file
    works while I save it as another application then all the parameters can not be
    seen from the include as file. I can only say it do happen.

    miaomm Guest

  4. #3

    Default Re: Included AS file cant access MXML varriables?

    For example, the following will generate a "Access of undefined property
    myString" error from the AS file.

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationPolicy="all">
    <mx:Script>
    <![CDATA[
    public var myString:String = "Bacon";
    include "myAS.as";
    ]]>
    </mx:Script>
    </mx:Application>

    --------------------------------------------------------------------------------
    ---------------------------------
    // myAS.as
    myString="Swine flesh";

    jfizer Guest

  5. #4

    Default Re: Included AS file cant access MXML varriables?

    In addition, import directives in the MXML don't make it to the Action Script file.
    jfizer Guest

  6. #5

    Default Re: Included AS file cant access MXML varriables?

    Try using import instead of include or use this
    mab_bond Guest

  7. #6

    Default Re: Included AS file cant access MXML varriables?

    [q]Originally posted by: mab_bond
    Try using import instead of include or use this[/q]

    Huh? Unless I'm missing something, import is for classes not source code files.
    jfizer Guest

  8. #7

    Default Re: Included AS file cant access MXML varriables?

    This is getting ridiculous. If I cant use include files, what good is this language? My project's over 3k lines so far, am I expected to put that all in one big text file?
    jfizer Guest

  9. #8

    Default Re: Included AS file cant access MXML varriables?

    you can include as file without any problem, and also access all variables that
    are declared in including file, but remember you need to access variables from
    functions you cant just treat included as file as just one big function
    so inside your myAS.as
    myString="Swine flesh"; will not work
    but
    public function myfunction () {
    myString="Swine flesh";
    }

    will work.

    levancho Guest

  10. #9

    Default Re: Included AS file cant access MXML varriables?

    [q]Originally posted by: levancho
    you can include as file without any problem, and also access all variables
    that are declared in including file, but remember you need to access variables
    from functions you cant just treat included as file as just one big function
    so inside your myAS.as
    myString="Swine flesh"; will not work
    but
    public function myfunction () {
    myString="Swine flesh";
    }

    will work.[/q]

    Within the same function in my .as file I can access some <MXML> tags by id,
    but not others. No rhyme or reason. What finaly made me snap today was trying
    to access the HDividedBox by ID that was the parent of the other objects I'd
    been working with. Even though the line before and after within the function
    accessed the children within the HDividedBox, I got nothing but errors when I
    tried to change the properties of the HDividedBox itself.

    jfizer Guest

  11. #10

    Default Re: Included AS file cant access MXML varriables?

    Watch your attitude man, nobody wants to steal your code or something like.
    We're here the share as a community. Your problem is essentially a Design
    Patter, you should learn about OOP, and how to use it. If you wanna access an
    external variable you should create a class and define its properties, and so
    on... If you wanna develop huge application you ought to read OReilly
    ActionScript 3.0 Design Patterns.

    mab_bond Guest

  12. #11

    Default Re: Included AS file cant access MXML varriables?

    [q]Originally posted by: mab_bond
    Watch your attitude man, nobody wants to steal your code or something like.
    We're here the share as a community. Your problem is essentially a Design
    Patter, you should learn about OOP, and how to use it. If you wanna access an
    external variable you should create a class and define its properties, and so
    on... If you wanna develop huge application you ought to read OReilly
    ActionScript 3.0 Design Patterns.[/q]

    Was making no such implication, just saying that I cant share my code as much
    as I'd like to since I'm unable to reproduce the problem on smaller projects
    (shrug). And I'm not trying to access an external variable. I simply want the
    include directive to work as its supposed to. I am using it correctly, but the
    results are inconstant and strange. As I've already said, within the same block
    of <MXML> I can access some objects by ID but not others. There is no logical
    explanation that I can find.



    jfizer Guest

  13. #12

    Default Re: Included AS file cant access MXML varriables?

    Ugh, this is starting to make my head hurt.

    So today I uncommented the line of code that last night was causing errors. No
    change was made, but today it works fine. This is without a doubt a problem
    with the FLex Builder environment rather then a problem with the source code
    I'm working with.

    jfizer Guest

  14. #13

    Default Re: Included AS file cant access MXML varriables?

    any time you start seeing unexplained behavior in FB it is usually a good idea
    to restart FB and then do a clean build of your project. I do so at least twice
    a day. FB/Eclipse are very far from perfect, but usually they help more than
    they hurt.

    slaingod Guest

  15. #14

    Default Re: Included AS file cant access MXML varriables?

    [q]Originally posted by: slaingod
    any time you start seeing unexplained behavior in FB it is usually a good idea
    to restart FB and then do a clean build of your project. I do so at least twice
    a day. FB/Eclipse are very far from perfect, but usually they help more than
    they hurt.[/q]

    I know and I did that yesterday. I really wish I could explain the behavior
    I'm seeing. But it's just defying all logic.

    However, as a backup, does anyone have a list of what parameters I would need
    to use to compile from the command line with the data visualization objects?
    Not sure of the class paths off hand.


    jfizer Guest

  16. #15

    Default Re: Included AS file cant access MXML varriables?

    "I can access some objects by ID but not others. There is no logical
    explanation that I can find."

    if you want to access all objects by id withing same mxml block, than you are
    doing something very very wrong, basically that means you are building
    application where all objects are siblings and none of them have children,
    mxml ids are basically same as variable names, so that means you can only
    access mxml objects bt id, ifare defined within same block of mxml, you can
    not access mxml objects by id if the are defined outside of the block, or even
    inside of the other object which is defined inside your block.

    IMHO, best way to help is on example, since your code carries proprietory
    nature, you can write a similiar bogus example that shows how you are trying
    to access, objects tc ... and what error you are getting ,that should not take
    you more than 5 monutes, that way it will be easier for guys to help you
    and I think it will finaly save you more frustration and angrey development
    days :)

    Kind Regards.


    levancho Guest

  17. #16

    Default Re: Included AS file cant access MXML varriables?

    Not sure I understand what your saying. Of course my MXML objects have parents
    and children, but when I had problems I could access the children but not the
    parent by ID. In this case it was because I was working on dynamicly resizing
    the sections of a HDividedBox and was under the miss impression that I needed
    to resize the children rather then setting the divider position.

    As for providing an example, the problem is that the issues comes and goes. So
    even if I could provide source code, there is no reason to expect that anyone
    else would see the problem with the example I could provide.

    jfizer Guest

  18. #17

    Default Re: Included AS file cant access MXML varriables?

    Object A can access its children with ids: (b,c,d) (which is same as by
    variable name) because they are part of that object ,so somewhere in object A
    there is code :
    b = childOne
    c = childTwo
    d = childThree
    thats why objct A can say c.doSomething, b.doSomething else etc ...
    but
    Object A can not access its parent (f) By id ,because
    Object A does not have :
    f = parentObject
    (although DisplayObject has property called "parent" which is invented for
    that reason so one DisplayObject can cascade up the hierarchy to its parent etc
    ....).


    levancho Guest

  19. #18

    Default Re: Included AS file cant access MXML varriables?

    [q]Originally posted by: levancho
    [Q]Originally posted by: jfizer
    Not sure I understand what your saying. Of course my MXML objects have parents
    and children, but when I had problems I could access the children but not the
    parent by ID..[/Q]
    Object A can access its children with ids: (b,c,d) (which is same as by
    variable name) because they are part of that object ,so somewhere in object A
    there is code :
    b = childOne
    c = childTwo
    d = childThree
    thats why objct A can say c.doSomething, b.doSomething else etc ...
    but
    Object A can not access its parent (f) By id ,because
    Object A does not have :
    f = parentObject
    (although DisplayObject has property called "parent" which is invented for
    that reason so one DisplayObject can cascade up the hierarchy to its parent etc
    ....).
    [/q]

    You seem to be off on some strange tangent. Its simple, I have for example
    MXML as follows...

    <mx:HDividedBox id="daBox" width="100%" height="100%">
    <mx:Canvas id="daCanvas" label="Canvas 1" width="100%"
    height="100%" backgroundColor="#FFFFCC">
    <mx:Label id="daText" text="Add components here"
    fontWeight="bold"/>
    </mx:Canvas>
    <mx:Canvas label="Canvas 2" width="100%" height="100%"
    backgroundColor="#99CCFF">
    <mx:Label text="Add components here" fontWeight="bold"/>
    </mx:Canvas>
    </mx:HDividedBox>

    Now my action script code could change the properties of daCanvas or daText
    but not daBox. At least until it magically started working this morning (well
    yesterday morning by now). At a guess, this is a problem with the syntax
    checker, but because its intermittent its hard to really check.

    jfizer Guest

  20. #19

    Default Re: Included AS file cant access MXML varriables?

    <mx:HDividedBox id="daBox" width="100%" height="100%">
    <mx:Canvas id="daCanvas" label="Canvas 1" width="100%" height="100%"
    backgroundColor="#FFFFCC">
    <mx:Label id="daText" text="Add components here" fontWeight="bold"/>
    </mx:Canvas>
    <mx:Canvas label="Canvas 2" width="100%" height="100%"
    backgroundColor="#99CCFF">
    <mx:Label text="Add components here" fontWeight="bold"/>
    </mx:Canvas>
    </mx:HDividedBox>

    ----------

    IT IS NOT POSSIBLE to access daCanvas and daText by just their Id from
    same function of same included AS file eitheryou can not access them at all,
    or can access one or the other, not both.

    I suggest you read developer Guide, at :
    [url]http://www.adobe.com/support/documentation/en/flex/[/url]
    it will make it clear.

    levancho Guest

  21. #20

    Default Re: Included AS file cant access MXML varriables?

    Levancho why do you say that isn't possible to access daCanvas and daText?
    mab_bond 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