passing

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
jemay
Posts: 6
Joined: 14 Jun 2011, 08:46

passing

Post by jemay »

Hello the expert!.

i'm using pro version & flash 10.0

i'm new in this, especially in java, but good in actionscript :)

why i got nothing(empty values) when i pass the array of objects??
ex: myArrayObj=[Person1,Person2,Person3]


//------------client side-------------------------

var obj:Object = {}
obj.myArrayObj = myArrayObj;
obj.test=new Array(1,2,3);


sfs.sendXtMessage(extensionName, "enter", obj)


//--------------server side-----------------------
ActionscriptObject arr1 = prms.getObj("myArrayObj");
ActionscriptObject arr2 = prms.getObj("test");

res.put("myArrayObj",arr1);
res.put("test",arr2);


//--------------return to flash(client side)-----------

i've got the right value for test>>>1,2,3
BUT,
i've got nothing for myArrayObj>>>got empty value



can anyone show me the right way how to do this...

any help!...TQ
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

How are Person1, Person2 and Person3 defined? What is their type?

Currently, the supported data types are: Array, Object, Boolean, Number and int.
Smartfox's forum is my daily newspaper.
jemay
Posts: 6
Joined: 14 Jun 2011, 08:46

Post by jemay »

Hi again!

Thanx for your quick reply.

Actually, the data type is a Class of Point (derived from Shape class)

so, the data will be an array of Point object.
this variable was defined from another class.

ex:
var myArrayObj:Array;
myArrayObj= new Array();

for (var px:uint = 0; px < 10; px++) {
for (var py:uint = 0; py < 10; py++) {
var point:Point = new Point();
addChild(point);
var id:uint=px+py*10;
point.id=id;
myArrayObj[id]=point;
point.x=21+42*px;
point.y=21+42*py;
point.init();
}
}



i wanted to retrieve back the same value (myArrayObj) inside flash.


thanks again for your time :)
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

SmartFoxServer does not support 'Point' type , so therefore won't work. You will need to manually convert the required data into an Object before storing it inside myArrayObj.
Smartfox's forum is my daily newspaper.
jemay
Posts: 6
Joined: 14 Jun 2011, 08:46

Post by jemay »

Ok, thanks for the info.

then i need to pass vars as object instead of array.

any simple example on how to pass an object to server side (java) then get the response result inside flash.

I might mess around, sorry.

thanx again for your quick responce. I really appreciate it.
:)
Sarevok
Posts: 75
Joined: 12 Apr 2011, 22:12

Post by Sarevok »

I don't know flash, but you can easily send collection of Actionscript objects, or JSON objects to the client. Let's assume that you have class Point on server:

Code: Select all

public Class Point
{
        private int _x;
        private int _y;
        
        public Point(int x, int y)
        {
                _x = x;
                _y = y;
        }

        public int getX()
        {
                return _x
        }

        public int getY()
        {
                return _y
        }
        
If you store your server points as array or some collection, you can easily convert that data into collection of actionscript objects:

Code: Select all

          LinkedList<ActionscriptObject> points = new LinkedList<ActionscriptObject>(); 

          for(int i = 0; i < arrayOfPoints.length; i++)
          {
                  ActionscriptObject point = new ActionscriptObject(); 
                  point.putNumber("x", arrayOfPoints[i].getX());
                  point.putNumber("y", arrayOfPoints[i].getY());  
                  points.add(point);        
          }
Now you can send this collection back to client:

Code: Select all

                 ActionscriptObject response = new ActionscriptObject();
                 response.putCollection("points", points);

                  // and now just send it to users...
jemay
Posts: 6
Joined: 14 Jun 2011, 08:46

Post by jemay »

Thank you so much! You literally saved my day. I'll follow all the mentioned steps. Hopefully these work.

Thanx again to Sarevok & BigFish
:)
Post Reply