Tom Krcha's FlashRealtime

Hey amigo!
I am Tom Krcha, Gaming Evangelist at Adobe. These are my notes


HOWTO: Transfer Custom Object - C Native Extensions in AIR

February 16th, 2012

Sometimes you want to transfer custom objects instead of predefined ones (or basic types). This is very useful, for example, when you want to construct for instance an array of positions. Position is in this case defined by an object with x, y, z properties.

Let’s initiate an Array instance. I wrote a tutorial about that here HOWTO: Transfer Array and Vector from AS3 to C with AIR Native Extensions for iOS:

uint32_t arr_len = 10; // count of positions
FREObject objectsPosition = NULL;
FRENewObject((const uint8_t*)"Array", 0, NULL, &objectsPosition, NULL);
FRESetArrayLength(objectsPosition, arr_len);

Next we will define a custom Object, basically the same way as we did with the Array

// loop through array length and fill it with data
for(uint32_t i=0;i<arr_len;i++){
 
FREObject position;
// create an instance of Object and save it to FREObject position
FRENewObject((const uint8*)"Object", 0, NULL, &position,NULL);
 
// populate temporary vars x, y, z
FREObject xPos;
FREObject yPos;
FREObject zPos;
FRENewObjectFromInt32(10, &xPos);
FRENewObjectFromInt32(20, &yPos);
FRENewObjectFromDouble(30, &zPos);
 
// fill properties of FREObject position
FRESetObjectProperty(position, (const uint8*)"x", zPos, NULL);
FRESetObjectProperty(position, (const uint8*)"y", yPos, NULL);
FRESetObjectProperty(position, (const uint8*)"z", zPos, NULL);
 
// add position to the array
FRESetArrayElementAt(objectsPosition, i, position);
}

Done. Have fun.

Facebook comments:

3 Comments »

  1. Hi,
    I’m trying to figure it out on the basis of Your post but when I do something like this:
    [code]
    FREObject dic;
    if(FRENewObject((const uint8_t *)"flash.utils.Dictionary",0, NULL, &dic, NULL)==FRE_OK){

    NSString *returnString = [NSString stringWithString:[[UIDevice currentDevice]uniqueIdentifier]];
    NSLog(@"UID: %@",returnString);

    const char *str = [returnString UTF8String];

    [returnString release];
    FREObject retStr;
    FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t*)str, &retStr);

    FRESetObjectProperty(dic, (const uint8_t*)"UID", retStr, NULL);
    return dic;
    }else{
    return nil;
    }
    [/code]
    Please any help?

    Comment by Mat — February 23, 2012 @ 3:33 am

  2. Hi Mat, you might want to check my tutorial about casting basic types from AS3 to C here: http://www.flashrealtime.com/transfer-string-number-int-uint-bool-ane/
    There is a String explained.

    Comment by tom — February 23, 2012 @ 11:11 am

  3. Ok:) got it.. relesed unnececery.. and had some problems on as3 side.. thanks.

    Comment by Mat — February 24, 2012 @ 12:22 am

RSS feed for comments on this post. / TrackBack URL

Leave a comment

Comment moderation is enabled. Your comment may take some time to appear.