header
ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
shrikumar
Points:50
Posts:0

7/29/2010 10:14:20 PM

Title: Need Help in BlazeDS remote Object(Repost)


Hi,

I need a help in Blazeds.

Here is my sample code




public function  getObjective():void    
        {    
            var  ro:RemoteObject= new mx.rpc.remoting.mxml.RemoteObject;    
            ro.destination="getEntity";  
           // getobjectives(); is java method which return ArryList  
            ro.getobjectives();       
            ro.addEventListener(ResultEvent.RESULT,objectivesResultHandler);                      
        }    
            
        private function objectivesResultHandler(event:ResultEvent):ArrayCollection    
        {   var objectiveList:ArrayCollection= new ArrayCollection;    
            objectiveList=event.result as ArrayCollection;                  
            return objectiveList;    
        }

My problem is i am calling getObjective() function in one `for-loop`. I need to return result ArrayCollection from first function. or in simple, I need <b>single function</b> which invoke remote-object and return ResultEvent result as arrayCollection, So that i can call this function anywhere and get the ResultEvent results. I need this urgently.. Trying from last 2 days.... Please help if you have any idea in it Thanks in advance



1
Justin
Points: 260
Posts:0
7/29/2010 11:45:16 PM



Calling getObjective() function in for loop will cause the " var ro:RemoteObject" to be declared again and again and overwrite the old one quickly before it receives its event.

First of all you should check it calling single time without through loop. If it works then your problem is the same that I am telling you.

Then you should declare an array to store the reference of your remote object
see this



private var refArray:Array = new Array();
public function  getObjective():void      
        {      
            var  ro:RemoteObject= new mx.rpc.remoting.mxml.RemoteObject;  
            ro.addEventListener(ResultEvent.RESULT,objectivesResultHandler);     
            ro.destination="getEntity";    
           // getobjectives(); is java method which return ArryList    
          
            ro.getobjectives(); 
            //store its reference in array so that its not lost
            refArray.push(ro);      
                                   
        } 


2
shrikumar
Points: 50
Posts:0
7/30/2010 1:07:07 AM



hi Justin ,

No, your code not working for my case.

here is simple explanation,

I need to show some panel and some buttons in that panel.
consider we have 5 panels, so i use for loop for 1 to 5.

inside that panels Button name comes from java
using remoteObject and blazeds.

Now my problem is remote object method not returning any value since it has void return type.
Following example may give u better understanding.





for(var m:int=0;m<=4;m++)
{
var outerPanel:Panel= new Panel;
outerPanel.titile=m;
this.addElement(outerPanel);

// object of 2nd class which(Should fetch, but its not happening) fetch the value from remoteObject
  var rmObj:remoteObjectClass = new remoteObjectClass();

var arc:ArrayCollection= new ArrayCollection();
  arc=rmObj.getRemoteData(m);

for(var n:int=0;n<=arc.length;n++)
{
  var testBut:Button= new Button();
   testBut.name=arc[n];
outerPanel.addElement(testBut);

}

}



Now here is the functions in RemoteObjectClass






          public function  getObjective(m:Int):void    
        {    
            var  ro:RemoteObject= new mx.rpc.remoting.mxml.RemoteObject;    
            ro.destination="getEntity";  
           // getobjectives(); is java method which return ArryList  
            ro.getobjectives(m);        
            ro.addEventListener(ResultEvent.RESULT,objectivesResultHandler);                      
        }    
            
        private function objectivesResultHandler(event:ResultEvent):ArrayCollection    
        {   var objectiveList:ArrayCollection= new ArrayCollection;    
            objectiveList=event.result as ArrayCollection;                  
            return objectiveList;    
        }

Hope you understand my problem

3
Troy
Points: 160
Posts:0
7/30/2010 1:24:57 AM



you are calling function arc=rmObj.getRemoteData(m); but in your class the name of function is getObjective(m)

4
Shawn
Points: 270
Posts:0
7/30/2010 1:38:46 AM



your class code seems fine . Have you traced the results in listener function "objectivesResultHandler" .

The process of calling remote methods is not synchronous so the result is not immediately available. when you call a remote method it wont return you data instantly in return.

so calling arc=rmObj.getRemoteData(m); will not return you anything.

I think you need to pass the reference of some listener function to that class so that it can call back when data is received. i.e

arc=rmObj.getRemoteData(m,callBackFunction);

and in class should callback and pass the objectiveList back

callBackFunction(objectiveList)

5
shrikumar
Points: 50
Posts:0
7/30/2010 2:31:00 AM



@ Shawn
Thanks..

But still i can't..
Can you please do me a favor,
Can you give me the code for below problem?






//I need to show some panel and some buttons in that panel. 
consider we have 5 panels, so i use for loop for 1 to 5. 

inside that panels Button name comes from java 
using remoteObject and blazeds. 



Post your Reply
Name  

Email

Type your Reply or Answer

Are you human? What is 7+4 



Members Login

Email  
Password
Forgot Password





This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions