Professional Web Applications Themes

Flex project, action script classes - Macromedia Flex General Discussion

Hey all, I am learning flex and ActionScript. I have a Flex project that I am playing with, and I am trying to learn how to work with ActionScript classes. I get an error of Access of Undefined property in my code. Here is my Flex app: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import com.Example; public var test:Example = new Example; test.Happy(); ]]> </mx:Script> </mx:Application> Here is my action script class: package com { public class Example { public function Example() { trace('WTF'); } public function Happy():void { trace('Is Happy Working????'); } } } In my project when ...

  1. #1

    Default Flex project, action script classes

    Hey all, I am learning flex and ActionScript. I have a Flex project that I am
    playing with, and I am trying to learn how to work with ActionScript classes.
    I get an error of Access of Undefined property in my code.
    Here is my Flex app:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
    <![CDATA[
    import com.Example;
    public var test:Example = new Example;
    test.Happy();

    ]]>
    </mx:Script>
    </mx:Application>

    Here is my action script class:
    package com
    {
    public class Example
    {
    public function Example()
    {
    trace('WTF');
    }
    public function Happy():void
    {
    trace('Is Happy Working????');
    }
    }
    }

    In my project when I create an instance of the class
    public var test:Example = new Example; I see the trace WTF work fine.
    When I call the Happy method test.Happy(); I get an error.... Access of
    Undefined property test.

    What am I doing wrong.
    Thanks for the help,
    timgerr1

    timgerr1 Guest

  2. #2

    Default Re: Flex project, action script classes

    Ok, Like I might have said, I am new to Flex and action script. Is there a
    different way to add a ActionScript components to a Flex application than
    adding an ActionScript class component to an ActionScript Application?

    If I take the same component package and add it to an ActionScript application
    then all works but not doing the same with Flex. What is the difference?

    Thanks,
    Timgerr1

    timgerr1 Guest

  3. #3

    Default Re: Flex project, action script classes

    Why am I unable to call methods when it is not in the main class method?

    Timgerr1
    timgerr1 Guest

  4. #4

    Default Re: Flex project, action script classes

    Because of the way mxml is generated into AS, thenthe AS ig compiled into the
    swf, you cannot access anything instantiated outside of a function immediately.
    "test" does not yet exist when you run:
    test.Happy();

    Put that call into an init function, or call it from a button and it will work.

    Avoid doing anything but declaring and initializing vars outside of a function.

    Tracy

    ntsiii Guest

  5. #5

    Default Re: Flex project, action script classes

    [q]Originally posted by: ntsiii
    Because of the way mxml is generated into AS, thenthe AS ig compiled into the
    swf, you cannot access anything instantiated outside of a function immediately.
    "test" does not yet exist when you run:
    test.Happy();

    Put that call into an init function, or call it from a button and it will work.

    Avoid doing anything but declaring and initializing vars outside of a function.

    Tracy[/q]

    Again, I am new, can you please post an example of using an int function or
    calling it from a button. I am not trying to be a pain, I just want to learn.

    Thanks for the help,
    Timgerr1

    timgerr1 Guest

Similar Threads

  1. Action Script Project and MXML
    By arenaBoy in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: May 14th, 08:50 AM
  2. Flex 2 Project in Flex 3 Swf File Size Increase?
    By Arty13 in forum Macromedia Flex General Discussion
    Replies: 4
    Last Post: April 17th, 07:10 PM
  3. flex/action script unit tests
    By joeblade in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: October 12th, 05:37 PM
  4. How to instantiate a Flex component with Action Script?
    By LordAlex in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: May 24th, 03:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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