Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
dam85 #1
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
-
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... -
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... -
#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: ... -
#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: ... -
#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... -
peterent #2
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
-
dam85 #3
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
-
dam85 #4
Re: Problem about importing class
i wrote the same rows read from adobe flex online manual. :(
dam85 Guest
-
peterent #5
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
-
dam85 #6
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
-
-
peterent #8
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
-



Reply With Quote

