Hi - I think what I'm trying to do is fundamental but I'm not doing it correctly. I have a swf that has a few different textFields appearing when buttons are clicked. I thought I could write one function that would handle the creation of all the textFields so that I could just put a few parameters into the function call at the onRelease. So is there a way to make this code into a function (like "makeTF") such that I could replace "block_txt" with any string I want and call the function like : makeTF(AnyString, depth, 110,90, 200,60); ?? I appreciate any help with this. jl // this works on its own but how do I make a functio this.createTextField("block_txt",this.getNextHighestDepth,x,y,width,height); block_txt._x=100; block_txt._y=60; block_txt._width=200; block_txt._height=60; //block_txt.autoSize = "left"; block_txt.border = true; block_txt.wordWrap = true; block_txt.html = true; block_txt.multiline = true; block_txt.html = true; block_txt.condenseWhite = true; block_txt.styleSheet = my_css; //t hen I would add text when I call the different TFs // block_txt.htmlText = "<h5>Whoa Baby</h5>";
: function makeTF(tfs:String, s:String, dep:Number, x:Number, y:Number, w:Number, h:Number){ this.createTextField(s,dep,x,y,w,h); with (this[s]){ border = true; wordWrap = true; html = true; multiline = true; html = true; condenseWhite = true; styleSheet = my_css; htmlText=tfs } }
Try this: var tf = makeTF("hey world", "1_tf", 0, 0, 100, 20); function makeTF(newText:String, id:String, x:Number, y:Number, width:Number, height:Number):TextField{ var newTf = this.createTextField(id,this.getNextHighestDepth,x,y,width,height); newTf.text = newText; return newTf; }
brycebarrand - Thanks. I'm not sure how to call this. When I put your code on fr1 and then called it on fr10 using different text in the quotes - all I got was your "hey world" from fr1 and not my text. I'll be calling this numerous times with different text. How can I make this work as you intended? TIA your help. jl makeTF("Got World?", "1_tf", 0, 0, 100, 20);
Hi kglad, Thanks for the response. This isn't sinking in. I put your code on fr1 and called it on frame 10 with the code below. All I got on the screen was a thin horizontal line about 40px long. Did you intend for me to add anything to your code? What am I missing? Thanks again, JL makeTF("Here is the text I want", 99,200,140,220,50);
Kglad - Got it! Thanks. jl as in......
However... I'm not getting any html results. If I put "<h1>some text</h1>" I'm not getting any thing different than if I left the <h1> out. Can this be fixed? Thanks again.
kglad - I'm always trying to understand more about coding so I hope you don't mind a question or two. I understand "s:String" on line 1 and how "s" is used in line 2 but I don't know "with (this[s])" means. What's going on here? Also - a weird thing - when I put your code into the actionscript window the syntax coloring went off such that some of the statements under "with (this[s])" are all blue and some are not. Is there something I can learn from that? Thanks for your instruction. JL function makeTF(tfs:String, s:String, dep:Number, x:Number, y:Number, w:Number, h:Number){ this.createTextField(s,dep,x,y,w,h); with (this[s]){ border = true; wordWrap = true; //all blue html = true; // all blue multiline = true; html = true; // repeated intentionally? all blue too condenseWhite = true; styleSheet = my_css; htmlText=tfs // the only one that's all black } }
array notation is used by flash to convert strings to objects. so, while s is a string this[s] is an object (the textfield with instance name s). and the only thing i infer from some properties being highlighted in blue and others not, is that the flash compiler is less than flawless.
kglad - I think I get it - that anything in square brackets is an array. (its the simple things that mean so much). As far as the flash compiler - you're being modest. You just brought it beyond the limits of its function...nice work! Thanks for all the coaching. jl
Don't see what you're looking for? Try a search.
|