Problem about importing class

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

  1. #1

    Default Problem about importing class

    Hello,
    i have this code.

    <!-- NameProject.mxml -->
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:my="components.*" width="100%" height="100%">

    <mx:Script>
    <![CDATA[
    import lib.User;
    public var u:User = new User();

    trace(u.say("hello world"));
    ]]>
    </mx:Script>
    </mx:Application>


    <!-- /lib/User.as -->
    package lib{
    public class User{
    public function say(s:String):String{
    return s;
    }
    }
    }


    i get this error:

    1120 Access of undefined property

    Why??

    thanks so much

    dam85 Guest

  2. Similar Questions and Discussions

    1. class problem (class)
      i have two class and i create them but i dont assign a value and run the subroutines.. what is my mistake? the error is --- Object...
    2. Importing a class into mx2004
      Hi, i've been trying to import a class into mx2004 (XFactorStudio Xpath class) I've set the classpath (publish setting/ as 2.0 settings) to this...
    3. #26364 [Opn->Bgs]: initializing class in other class vars value problem
      ID: 26364 Updated by: sniper@php.net Reported By: brightone at o2 dot pl -Status: Open +Status: ...
    4. #26364 [Bgs->Opn]: initializing class in other class vars value problem
      ID: 26364 User updated by: brightone at o2 dot pl Reported By: brightone at o2 dot pl -Status: Bogus +Status: ...
    5. #26364 [NEW]: initializing class in other class vars value problem
      From: brightone at o2 dot pl Operating system: windows xp PHP version: 4.3.4 PHP Bug Type: Class/Object related Bug...
  3. #2

    Default Re: Problem about importing class

    You have this statement: trace(u.say("hello world")); but it isn't not inside
    any function. That may be the problem. I don't know off the top of my head if
    the error you are getting is a compile-time or runtime error. Which is it?

    peterent Guest

  4. #3

    Default Re: Problem about importing class

    [q]Originally posted by: peterent
    You have this statement: trace(u.say("hello world")); but it isn't not inside
    any function. That may be the problem. I don't know off the top of my head if
    the error you are getting is a compile-time or runtime error. Which is it?[/q]

    i see this error when i do a 'clear' on my adobe flex builder


    1120 Access of undefined property u.

    dam85 Guest

  5. #4

    Default Re: Problem about importing class

    i wrote the same rows read from adobe flex online manual. :(
    dam85 Guest

  6. #5

    Default Re: Problem about importing class

    You have this Script block in your code:
    <mx:Script>
    <![CDATA[
    import lib.User;
    public var u:User = new User();

    trace(u.say("hello world"));
    ]]>
    </mx:Script>

    The trace statement is just "floating" in there - it must be in a function.
    When do you want this trace executed? For example, if you want to display it
    when the Application dispatches its creationComplete event, then add a
    creationComplete event handler to the Application tag and then write the
    function to handle the event in the Script block:

    <mx:Application ... creationComplete="iniApp()">

    <mx:Script>
    <![CDATA[
    import lib.User;
    public var u:User = new User();

    private function initApp() : void {
    trace(u.say("hello world"));
    }
    ]]>
    </mx:Script>

    Now the trace statement appears in a function so you will not get the error.

    peterent Guest

  7. #6

    Default Re: Problem about importing class

    yes, very good! now works!!!

    thanks so much.....the last question...

    but if i create an instance of a class in my main.mxml

    example:
    public var s:User = new User();

    i can write a function, like this

    public function getMyObj():User{
    return s;
    }

    i think this code should works, but how can i call this function (getMyObj())
    in other .mxml files?

    i hate to use the same class instance for every mxml file

    how could i do?

    thanks again







    dam85 Guest

  8. #7

    Default Re: Problem about importing class

    ....i have to use.... NOT i "HATE" :)
    dam85 Guest

  9. #8

    Default Re: Problem about importing class

    From any class in your application you can do this:

    import NameProject;

    var app:NameProject = Application.application as NameProject;
    var u:User = app.getMyObj();
    peterent Guest

  10. #9

    Default Re: Problem about importing class

    perfect!!! thanks
    dam85 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