tag:robotlegs.tenderapp.com,2009-10-18:/discussions/questions/959-instantiate-and-utilize-class-from-within-robotlegs-mvcsRobotlegs: Discussion 2012-08-25T14:41:04Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/172156602012-07-11T00:06:58Z2012-07-11T00:06:59ZInstantiate and utilize class from within robotlegs mvcs<div><p>Hi,</p>
<p>I'm primarily a Flash CS5/AS3 developer, but am trying to make
the transition to Flash Builder 4 using the robotlegs framework. If
I could understand how to utilize this class within Flash Builder
using mediators, I think I'd be well on my way.</p>
<p>Within Flash I import an external class and instantiate like
so:</p>
<p>import CreateTextBlock;<br>
var TextCreator:CreateTextBlock = new CreateTextBlock();<br>
function InitText()<br>
{</p>
<pre>
<code>addChild(TextCreator);</code>
</pre>
<p>}<br>
InitText();</p>
<p>Then I call the class and populate like so:</p>
<p>//This typically comes from json consumption, but for this
purpose... var lessonTitle:String = "The string to populate the
text block";</p>
<p>Then I call the function like so:<br>
TextCreator.CreateText(lessonTitle, "Headline_1", textWidth, textX,
textY, 0xFCAF17, 54, 1, true, 0);</p>
<p>Removal of the text:</p>
<p>var headLineText:DisplayObject =
MovieClip(root).getChildByName("Headline_1");<br>
if(headLineText != null)<br>
{</p>
<pre>
<code>MovieClip(root).removeChild(headLineText);
headLineText = null;</code>
</pre>
<p>}</p>
<p>The Class:</p>
<p>package<br>
{</p>
<pre>
<code>import flash.display.*;
import flash.text.*;
public class CreateTextBlock extends MovieClip
{
public var myTextField:TextField;// = new TextField();
public function CreateText(textString:String,
textName:String,
textWidth:Number,
textX:Number,
textY: Number,
textColor:int,
textSize:int,
fontStyle:int,
textWordWrap:Boolean,
myLeading:int):void
{
trace(textString);
trace(textName);
trace(textWidth);
trace(textX);
trace(textY);
trace(textColor);
trace(textSize);
trace(fontStyle);
trace(textWordWrap);
trace(myLeading);
}
}</code>
</pre>
<p>}</p>
<p>So, with that being said, I'm trying to format this based off
Joel Hook's 'Hello World' robotlegs tutorial. I understand the
adding and removal of the text needs to be mediated, and the class
should be converted into a service. If it's quick for someone to
convert my Flash paradigm above into the robotlegs paradigm, I
would very much appreciate it; else, any pointers would also be
appreciated. I've done a lot of work with Flash and as1,2 & 3
over the years, but making the transition to mvcs frameworks is a
bit of a struggle for me right now, but I want to understand and
start using robotlegs as my framework of choice.</p>
<p>Any help would be greatly appreciated,<br>
~Chipleh</p></div>Chiplehtag:robotlegs.tenderapp.com,2009-10-18:Comment/172156602012-07-11T00:09:56Z2012-07-11T00:09:56ZInstantiate and utilize class from within robotlegs mvcs<div><p>The entirety of my class looks like so:</p>
<p>package<br>
{</p>
<pre>
<code>import flash.display.*;
import flash.text.*;
public class CreateTextBlock extends MovieClip
{
public var myTextField:TextField;// = new TextField();
public function CreateText(textString:String,
textName:String,
textWidth:Number,
textX:Number,
textY: Number,
textColor:int,
textSize:int,
fontStyle:int,
textWordWrap:Boolean,
myLeading:int):void
{
myTextField = new TextField();
MovieClip(root).addChild(myTextField);
var myFont;
myTextField.name = textName;
if(fontStyle == 1)
{ myFont = new DinSchrift();
}else if(fontStyle == 2){ myFont = new Verdana();
}else if(fontStyle == 3){ myFont = new Skitch();
}else if(fontStyle == 4){ myFont = new Font4();
}
var myFormat:TextFormat = new TextFormat();
myFormat.font = myFont.fontName;
myFormat.leading = myLeading;
myTextField.defaultTextFormat = myFormat;
myTextField.embedFonts = true;
myTextField.htmlText = textString;
myTextField.width = textWidth;
myTextField.x = textX;
myTextField.y = textY;
myTextField.selectable = false;
myTextField.border = false;
myTextField.multiline = textWordWrap;
myTextField.wordWrap = textWordWrap;
myTextField.autoSize = TextFieldAutoSize.LEFT;
myFormat.color = textColor;
myFormat.letterSpacing = 0;
myFormat.size = textSize;
myFormat.italic = false;
myTextField.setTextFormat(myFormat);
}
}</code>
</pre>
<p>}</p>
<p>My goal is to add a singe text field to the Flash Builder stage
using the given formatting. If I can figure this out, the robotlegs
world will open. : )</p>
<p>Thanks again for any help.</p></div>Chiplehtag:robotlegs.tenderapp.com,2009-10-18:Comment/172156602012-07-11T00:33:58Z2012-07-11T00:33:58ZInstantiate and utilize class from within robotlegs mvcs<div><p>A full breakdown of your code into Robotlegs would take some
work and<br>
involves a number of concepts that aren't actually Robotlegs --
just<br>
encouraged by Robotlegs -- such as how to set up a display
hierarchy<br>
when you're doing all your display programming in code.</p>
<p>Having said that, here's an example I put together for an "Intro
to<br>
Robotlegs" hands on workshop that is similar to what you're saying
you<br>
want to do:<br>
(Robotlegs 2 version) <a href=
"http://goo.gl/3Vt06">http://goo.gl/3Vt06</a> (Robotlegs 1 version)
<a href="http://goo.gl/NcGb6">http://goo.gl/NcGb6</a></p>
<p>It doesn't load the text from a JSON file -- instead you select
a file<br>
with the OS file picker and the app gets the name of the file and
writes<br>
it to a text field on the screen. But that would just be a matter
of<br>
changing the code in the service class. It also doesn't do all
the<br>
formatting of the text field that your example specifies, but you
could<br>
do that by adding the code from your "CreateText()" method to
the<br>
simple.view.TextContainer class.</p>
<p>I hope this is helpful.</p>
<p>Paul</p></div>Paul Robertson