A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Copy variables from an object to another

  1. #1
    Member
    Join Date
    Dec 2001
    Posts
    30

    Copy variables from an object to another

    A simple thing, but what's the easiest way around?

    I've made an (Object class) object with all the TextField objects variable-value pairs in it (eg autoSize="left"; embedFonts=true; etc) . Now I'd like to copy these values into the newly created actual TextField object.

    Any suggestions what's the smartest and lightest way to script the variable copying process (I've got masses of TextFields...)?

    Cheers!

  2. #2
    Senior Member
    Join Date
    Mar 2000
    Posts
    177
    Code:
    // copy vars from a to b
    for (var p in a) {
        b[p] = a;
    }
    It's really as easy as that. You can make this into a function:
    Code:
    function copyVars (a, b) {
        for (var p in a) {
            b[p] = a;
        }
    }
    New Book: Robert Penner's Programming Flash MX
    Dynamic tweening, color, math, vectors and physics with OOP ActionScript
    http://www.robertpenner.com/profmx
    http://www.amazon.com/exec/obidos/AS...bertpennerc-20

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