Problem with a Class

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

  1. #1

    Default 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

  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. #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: ...
    3. #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: ...
    4. #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...
    5. Class problem
      consider this: ? class A { function A() { $b = 'hello world'; }
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default Re: Problem with a Class

    could you please show the code for Flex2Php class?
    atta707 Guest

  6. #5

    Default 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

  7. #6

    Default 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

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