A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How do I do this... C++ type pointers in Flash

  1. #1
    Junior Member
    Join Date
    Sep 2004
    Posts
    10

    How do I do this... C++ type pointers in Flash

    Hi everyone, I am veteran C++ programmer and new to flash. Kind of stuck here trying to populate an object with elements from an Array. Very easy in C using pointers but can't figure out a way of accomplishing it in Flash. Your help is greatly appreciated.

    /* Trying to populate my_lv object with array elements so that I may submit it to a php script via LoadVars.sendAndLoad for processing
    */

    // The array itself
    var myArray:Array = new Array();
    myArray[name] = "John Doe";
    myArray[age] = 25;
    myArray[height] = 70";

    // The object declaration
    var my_lv = new LoadVars();

    // Loop to go through array elements and populate the LoadVars object
    for (everyelement in myArray) {
    trace ("myArray[" + everyelement + "] = " + myArray[everyelementname]);

    // THIS IS WHERE I AM GETTING STUCK!!!
    my_lv. & everyelement = myArray[everyelement];
    // the & everyelement does not work because it makes no sense. Can someone please point me in a direction where I can make sense of it. Thanks.
    }


    BTW, the myArray.toString() function will not work for me because it only returns back the array data with the pointer name.

    Thanks,
    Mansoor Lakhani.

  2. #2
    Junior Member
    Join Date
    Sep 2004
    Posts
    10
    A function such as strcopy() will do the trick for me. I can't find any such function in ActionScript 2.0. Maybe someone can just point me towards that function. I can modify the code so that it looks like this

    // THIS IS WHERE I AM GETTING STUCK
    // A possible solution if I could find a strcopy function
    temp_string = "my_lv. " + everyelement;
    strcopy (temp_string, myArray[everyelement]);
    }

  3. #3
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I think this is what you want:

    my_lv[everyelement] = myArray[everyelement];

    let's say 'everyelement' is 'name'

    This will be the same as

    my_lv.name = myArray.name;

    There are no pointers in flash, to speak of, nor is there strcpy, but usually you can accomplish what you need via assignment. One of the odd things about flash is that

    obj[name]

    is the same thing as

    obj.name

    But the first method allows you to use dynamic names, since 'name' is evaluated.

    By the way, I'm also a veteran C/C++ programmer who learned actionscript...

  4. #4
    Junior Member
    Join Date
    Sep 2004
    Posts
    10
    Hello fellow C/C++ programmer. That so worked. You are so right when you say "the odd things about flash is" because it sure did evaluate the name when used with brackets. A very unusual syntax style but the darn thing worked. I was losing my mind last night trying to figure this out.

    Thanks a bunch,
    Mansoor Lakhani.

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