A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Moving from C (not C++) to AS3

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    24

    Question Moving from C (not C++) to AS3

    I'm moving some of my older C code (see below) to AS3, and have a couple of areas which I am researching how to convert, and wonder if anyone can assist?

    To give some context to the code below, "appearances" are when actors (game objects) are introduced into a game level, and an appearance is defined by an actor number, plus an X and Y position.

    A game level can be a title screen, the main game, game-over screen etc.

    For each level in the array levelAppearancesInfo, there is a pointer to another array containing details of the actual appearances, plus the number of appearances in that level.

    So in a nutshell, I'm looking to find out how to convert to AS3, from C, the following:

    (1) arrays of structs

    (2) an array containing a pointer to another array

    I do know that references will be replacing the pointers, and that classes will take the place of structs.

    I'm working on this right now, and any insights would be most appreciated.

    Here is the original C code that I wish to convert to AS3:

    Code:
    #define ACTOR_TITLE 0
    #define ACTOR_HERO 1
    #define ACTOR_MUTANT 2
    #define ACTOR_TREAT 3
    
    struct SAppearance
    {
    	int actorType;
    	int xpos;
    	int ypos;
    };
    
    struct SAppearance appearancesTitle[] =
    {
    	ACTOR_TITLE, 44, 78
    };
    
    
    struct SAppearance appearancesGame[] =
    {
    	ACTOR_HERO, 84, 199,
    	ACTOR_MUTANT, 26, 43,	
    	ACTOR_TREAT, 41, 15
    };
    
    struct
    {
    	struct SAppearance * pLevelAppearances;
    	int numAppearances;
    }
    levelAppearancesInfo[] =
    {
    	appearancesTitle, sizeof(appearancesTitle) / sizeof(appearancesTitle[0]),
    	appearancesGame, sizeof(appearancesGame) / sizeof(appearancesGame[0])
    };
    
    So, levelAppearancesInfo[0] contains the information for level 0 etc.
    Last edited by miner2049er; 12-14-2008 at 10:36 PM.

  2. #2
    Junior Member
    Join Date
    Aug 2007
    Posts
    24
    With my second question, it seems that something like:

    Code:
    		var array1:Array = new Array(1, 2, 3, 4, 5);
    		var array2:Array = new Array(6, 7, 8);
    		var array3:Array = [array1, array1.length, array2, array2.length];
    is on the way towards a solution, but I wonder if there is anything more elegant.

    I could even split it into two parallel arrays - one array containing references to the arrays, and another array containing their lengths.

    If anybody has any advice regarding my two questions in the first post, any help would still be most appreciated.

  3. #3
    Member
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    66
    You don't have to store the lengths of the arrays.

    PHP Code:
    array3[0].length 
    Should work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center