Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
dam85 #1
Problem with a Class
I have this class
this class works good, the trace() inside completeHandler() print the response
of the php page....
but when i call this class from another .as file i get an error when i try to
do event.target.data
i call the class with:
private function getUserInvited():void{
var http:Flex2Php = new Flex2Php();
http.addEventListener("COMPLETE", eventUserInvited)
http.connect("http://www.example.it/test.php", "POST");
http.setVariables("id_a="+Application.application. userId);
http.send();
}
private function eventUserInvited(event:Event):void{
trace(event.target.data);
}
the error is:
ReferenceError: Error #1069: Property data not found on inc.Flex2Php and there
is no default value.
at
components::UsersList/eventUserInvited()[/home/damiano/lavoro/flex/MyProject/src
/components/inc/UsersList.as:38]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at
inc::Flex2Php/completeHandler()[/home/damiano/lavoro/flex/MyProject/src/inc/Flex
2Php.as:18]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
how can i pass the response data from my class (Flex2Php) to the
eventUserInvited() ??
Thanks a lot
P.S. I don't want to put -> var http:Flex2Php = new Flex2Php(); (public)
package inc{
import flash.events.*;
import flash.net.*;
public class Flex2Php extends EventDispatcher{
public var loader:URLLoader = new URLLoader();
public var request:URLRequest = null;
public function Flex2Php():void{
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, completeHandler);
}
public function completeHandler(event:Event):void{
trace("DATA RECEIVED: " + String(event.target.data));
dispatchEvent(new Event("COMPLETE"));
}
public function connect(url:String, method:String):void{
request = new URLRequest(url);
if (method == "POST"){
request.method = URLRequestMethod.POST;
}
else{
request.method = URLRequestMethod.GET;
}
}
public function setVariables(vars:String):void{
var variables:URLVariables = new URLVariables(vars);
request.data = variables;
}
public function send():void{
loader.load(request);
}
}
}
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... -
#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... -
Class problem
consider this: ? class A { function A() { $b = 'hello world'; } -
atta707 #2
Re: Problem with a Class
add new public property in your Flex2Php class and in the complete handler say:
this.data = event.target.data;
atta707 Guest
-
dam85 #3
Re: Problem with a Class
ok i added this new variable, to retrieve it what can i do?
have i to change this
var http:Flex2Php = new Flex2Php();
to
public var http:Flex2Php = new Flex2Php();
??
is it the only way?
Tnanks
dam85 Guest
-
atta707 #4
Re: Problem with a Class
could you please show the code for Flex2Php class?
atta707 Guest
-
prmbevis #5
Re: Problem with a Class
Add a new public property to your Flex2Php class called data and have it return the data property of the encapsulated loader i.e.
public function get data () : Object
{
return loader.data;
}
prmbevis Guest
-
dam85 #6
Re: Problem with a Class
this is the code
Bye bye
// This is the class to send/retrieve data
package inc{
import flash.events.*;
import flash.net.*;
public class Flex2Php extends EventDispatcher{
public var loader:URLLoader = new URLLoader();
public var request:URLRequest = null;
public var data:String = new String();
public function Flex2Php():void{
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, completeHandler);
}
public function completeHandler(event:Event):void{
data = event.target.data;
dispatchEvent(new Event("COMPLETE"));
}
public function connect(url:String, method:String):void{
request = new URLRequest(url);
if (method == "POST"){
request.method = URLRequestMethod.POST;
}
else{
request.method = URLRequestMethod.GET;
}
}
public function setVariables(vars:String):void{
var variables:URLVariables = new URLVariables(vars);
request.data = variables;
}
public function send():void{
loader.load(request);
}
}
}
//Caller
private function send():void{
var http:Flex2Php = new Flex2Php();
http.addEventListener("COMPLETE", function():void { myEvent(http.data); })
http.connect(Application.application.pageSendInvit e, "POST");
http.setVariables("id_a="+Application.application. userId);
http.send();
}
private function myEvent(data:String):void{
trace(data);
}
dam85 Guest



Reply With Quote

