A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: TextField.prototype.addShadow(); help plz!

Hybrid View

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

    TextField.prototype.addShadow(); help plz!

    Hi Fellow Flashers,
    I wrote this prototype that adds a dropshadow to any TextField object. It works great as long as the TextField object is on the _root. If I try to use the prototype on any TextField object contained within a MovieClip, the dropshadow text gets created, but all text nowhere to be seen(maybe it's off the stage, maybe its a depth() thing, maybe its a target thing, I dunno..) Can anyone find my mistake(s):
    Code:
    TextField.prototype.addShadow = function (shadowColor){
    	// create some objects to hold info about our original Txt field
    origTxtProps = new Object();
    origTxtFormat = this.getTextFormat();
    newTxtFormat = new TextFormat(); 
    
    for(var i in this){ // archive the original Txt properties
    	origTxtProps[i] = this[i];
    }
    for(var i in this.getTextFormat()){ // add original TextFormat values to a new TextFormat
    	newTxtFormat[i] = this.getTextFormat()[i];
    	//trace("format property: "+i+" = "+origTxtFormat[i]);
    }
    this._parent.createEmptyMovieClip(this._name + "Holder", this.getDepth()+1); // put the text into a MC for easy manipulation
    path = this._parent[this._name + "Holder"]; // truncate MC path
    
    // create new text fields to be populated with data from the original text
    path.createTextField("bottomTxt",17000, 0, 0, this._x, this._y, origProps.textWidth, origProps.textHeight);
    path.createTextField("topTxt",170001, 0, 0, this._x, this._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 = shadowColor; // 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 = this._x; 
    path._y = this._y;
    
    // render the original TxtField untouchable, How can i remove it from memory??
    this.selectable = false;
    this.text = "";
    };
    
    // usage that works
    test.addShadow(0xffff00);
    
    // usage that doesn't work
    myMC.test.addShadow(0xffff00);
    Thanks for the future,
    ~Dev

  2. #2
    Member
    Join Date
    Mar 2001
    Posts
    71

    how does this work?

    Hi. I don't understand how this works. Where does this code go? I'm trying to apply a dropshadow to multiple MC of text in my movie. Is this how I accomplish this? Any feedback would be appreciated. Thanks.

  3. #3
    ActionScript Insomniac
    Join Date
    Jan 2003
    Location
    43d03.21'N, 89d23.65'W
    Posts
    1,173
    Your created holder clip was likely tromping on top of myMC. You need to get a clear depth.

    Also, you have too many parameters in createTextField, and potentially could have zero width or height, making the new text not visible.

    Minor problem with x and y confusion.

    If a textfield is created using MovieClip.createTextField(), you can remove it with this.removeTextField(). If created at authoring time, I don't know a way to remove it.

    code:


    this._parent.createEmptyMovieClip(this._name + "Holder", this._parent.getNextHighestDepth());


    ..

    path.createTextField("bottomTxt",1, 0, 0, origTxtProps.textWidth, origTxtProps.textHeight);
    path.createTextField("topTxt", 2, 0, 0, origTxtProps.textWidth, origTxtProps.textHeight);

    ...

    path.topTxt._x = path.bottomTxt._x - 1;




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