C++ Union in Actionscript 3

Creating a union similar to c/c++ in Actionscript

Page 1 of 1

2 Replies - 2687 Views - Last Post: 12 December 2008 - 08:55 AM

#1 omargalsoolker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-December 08

C++ Union in Actionscript 3

Posted 06 December 2008 - 09:12 AM

I am relatively new to Actionscript and have a c/c++ background.

I would like to know if there is any way one can implement a c/c++ union in Actionscript 3?
I have found my own way to do this, but I have to write quite a lot of actionscript code to achieve this.

Can anybody please HELP!!!
Is This A Good Question/Topic? 0
  • +

Replies To: C++ Union in Actionscript 3

#2 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 5751
  • View blog
  • Posts: 10,076
  • Joined: 28-September 07

Re: C++ Union in Actionscript 3

Posted 06 December 2008 - 12:10 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 omargalsoolker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-December 08

Re: C++ Union in Actionscript 3

Posted 12 December 2008 - 08:55 AM

#define MAX_CARGO 1000
#define LEN_CODE 50
#define LEN_DESC 100
#define LEN_RANGENAME 250

/*-----------------------------------------------------------------*/
/* M_GENERIC : Useful for sending or retrieving various data types */
/*-----------------------------------------------------------------*/
typedef struct
{
char parm1;
char parm2[LEN_CODE];
char parm3[LEN_CODE];
char parm4[LEN_CODE];
char parm5[LEN_DESC];
char parm6;
long parm7;
char parm8[LEN_RANGENAME];
} M_GENERIC;

/*------------------------------*/
/* M_SIMPLE : A stream of bytes */
/*------------------------------*/
typedef struct
{
char cargo[MAX_CARGO];
} M_SIMPLE;

typedef struct
{
ULONG sessID;
char srcID;
char dstID;
USHRT msgID;
ULONG seq;
union
{
M_SIMPLE mSimple;
M_GENERIC mGeneric;
} u;
} MYMSG;

These structures are used in a server socket program. I request data from the server by passing it 'msgID', so that
the server knows the type of response to send back and also where to send it to. The server knows the
source 'srcID'of the request and also the destination 'dstID' it needs to send it to.

In my actionscript application, I am using binary sockets to make the connection and requests to this server.
I don't have any problems sending the request, but when I read from the stream, I need to read all bytes
from the server into a structure (MYMSG), such that once read, all I have to do on the actionscript side is to check
the msgID and knowing what it is, I would simply reference for example 'mSimple', because the msgID indicates that
the server had sent data based on this type of structure.
So then, in a c/c++ app, I would reference it like so: u.mSimple.cargo.

Currently, in my actionscript code, I read all bytes into a byte array, but have to painstakingly split the data
into what I require. This would be fine if the server were only to send perhaps two differebt data types, but in reallity
it is not so. There could upto 600 didferent types of messages I could request and receive from the server.

Is there anyway, in actionscript to achieve a 'MYMSG' structure to include a union, or something similar??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1