A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: how to duplicate a TextField exactly?

  1. #1
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    how to duplicate a TextField exactly?

    Hi,
    I'm trying to figure out whats the best way to duplicate a TextField with the EXACT properties of TextField it was duplicated from. I want to grab all the properties from the original TextField(maybe in the form of an Object?), create an empty TextField, and populate it with all the properties of the original. What I have below I know is not right. I am populating an object with the proper variables but then I am setting their values to a string of the variable name. I want the value of the variable not it's identifier.
    Code:
    origProps = new Object();
    for(var i in test){
    	origProps[i] = i;
    	trace(origProps[i]);
    }
    if you list the variables in origProps it looks like this:
    Variable _level0.origProps = [object #1, class 'Object'] {
    styleSheet:"styleSheet",
    mouseWheelEnabled:"mouseWheelEnabled",
    condenseWhite:"condenseWhite",
    restrict:"restrict",
    textHeight:"textHeight",
    textWidth:"textWidth",
    bottomScroll:"bottomScroll",
    length:"length",
    selectable:"selectable",
    multiline:"multiline",
    password:"password",
    wordWrap:"wordWrap",
    background:"background",
    border:"border",
    html:"html",
    embedFonts:"embedFonts",
    maxChars:"maxChars",
    maxhscroll:"maxhscroll",
    hscroll:"hscroll",
    variable:"variable",
    htmlText:"htmlText",
    type:"type",
    text:"text",
    autoSize:"autoSize",
    tabIndex:"tabIndex",
    textColor:"textColor",
    backgroundColor:"backgroundColor",
    borderColor:"borderColor",
    maxscroll:"maxscroll",
    scroll:"scroll"
    }

    What is the syntax for getting the value of the variables?

    DUH?
    ~Dev

  2. #2
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    DUh?

    oops that was simple, I got it to work like this(test is the name of my TextField):
    Code:
    origProps = new Object();
    for(var i in test){
    	origProps[i] = test[i];
    	trace("property: "+i+" = "+origProps[i]);
    }
    next thing to do is to get all the values from origProps and use them on the new TextField. I'll post my code for those interested once I write it

    ~Dev

  3. #3
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196

    DropShadow code

    Well here is what I came up with, I'm not so sure this is the most efficient way to do things if anyone has a better way please let me know.
    test is the name of my dynamic textfield on the stage(I wrote TEST 123 inside the field). I'm gonna make this code into a function next. How can I remove a TextField from the stage(and memory) if it was not created by a createTextField command? I put both peices of text into a MC becaue I could not manipulate the depths of the TextFields, it seems swapDepths() only works for MovieClips.
    Code:
    // create some objects to hold info about our original Txt field
    origTxtProps = new Object();
    origTxtFormat = test.getTextFormat();
    newTxtFormat = new TextFormat(); 
    
    for(var i in test){ // archive the original Txt properties
    	origTxtProps[i] = test[i];
    }
    for(var i in test.getTextFormat()){ // add original TextFormat values to a new TextFormat
    	newTxtFormat[i] = test.getTextFormat()[i];
    	//trace("format property: "+i+" = "+origTxtFormat[i]);
    }
    test._parent.createEmptyMovieClip("holder", test.getDepth()+1); // put the text into a MC for easy manipulation
    path = test._parent.holder; // truncate MC path
    
    // create new text fields to be populated with data from the original text
    path.createTextField("bottomTxt",17000, 0, 0, test._x, test._y, origProps.textWidth, origProps.textHeight);
    path.createTextField("topTxt",170001, 0, 0, test._x, test._y, origProps.textWidth, origProps.textHeight);
    for(var i in origTxtProps){ // populate and set props for the newly created text
    	path.topTxt[i] = origTxtProps[i];
    	path.bottomTxt[i] = origTxtProps[i];
    }
    
    // transfer original format to newly created text
    path.topTxt.setTextFormat(newTxtFormat); 
    path.bottomTxt.setTextFormat(newTxtFormat);
    
    path.bottomTxt.textColor = 0xffff00; // make the drop shadow color
    
    // nudge the top text to reveal the drop shadow underneath
    path.topTxt._y = path.bottomTxt._y - 1;
    path.topTxt._x = path.bottomTxt._y - 1; 
    
    // set the MC that holds the text to the exact postion
    path._x = test._x; 
    path._y = test._y;
    
    // render the original TxtField untouchable, How can i remove it from memory??
    test.selectable = false;
    test.text = "";
    I hope I'm not re-inventing the wheel here
    ~Dev

  4. #4
    Senior Member
    Join Date
    Sep 2000
    Location
    San Francisco
    Posts
    196
    I made a TextField prototype out of the above code and moved this messy thread to a freshy:
    http://www.flashkit.com/board/showth...hreadid=510327

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