Instantiate and utilize class from within robotlegs mvcs

Chipleh's Avatar

Chipleh

11 Jul, 2012 12:06 AM

Hi,

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.

Within Flash I import an external class and instantiate like so:

import CreateTextBlock;
var TextCreator:CreateTextBlock = new CreateTextBlock();
function InitText()
{

addChild(TextCreator);

}
InitText();

Then I call the class and populate like so:

//This typically comes from json consumption, but for this purpose... var lessonTitle:String = "The string to populate the text block";

Then I call the function like so:
TextCreator.CreateText(lessonTitle, "Headline_1", textWidth, textX, textY, 0xFCAF17, 54, 1, true, 0);

Removal of the text:

var headLineText:DisplayObject = MovieClip(root).getChildByName("Headline_1");
if(headLineText != null)
{

MovieClip(root).removeChild(headLineText);
    headLineText = null;

}

The Class:

package
{

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);
    }       
}

}

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.

Any help would be greatly appreciated,
~Chipleh

  1. 1 Posted by Chipleh on 11 Jul, 2012 12:09 AM

    Chipleh's Avatar

    The entirety of my class looks like so:

    package
    {

    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);            
        }       
    }
    

    }

    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. : )

    Thanks again for any help.

  2. 2 Posted by Paul Robertson on 11 Jul, 2012 12:33 AM

    Paul Robertson's Avatar

    A full breakdown of your code into Robotlegs would take some work and
    involves a number of concepts that aren't actually Robotlegs -- just
    encouraged by Robotlegs -- such as how to set up a display hierarchy
    when you're doing all your display programming in code.

    Having said that, here's an example I put together for an "Intro to
    Robotlegs" hands on workshop that is similar to what you're saying you
    want to do:
    (Robotlegs 2 version) http://goo.gl/3Vt06
    (Robotlegs 1 version) http://goo.gl/NcGb6

    It doesn't load the text from a JSON file -- instead you select a file
    with the OS file picker and the app gets the name of the file and writes
    it to a text field on the screen. But that would just be a matter of
    changing the code in the service class. It also doesn't do all the
    formatting of the text field that your example specifies, but you could
    do that by adding the code from your "CreateText()" method to the
    simple.view.TextContainer class.

    I hope this is helpful.

    Paul

  3. Ondina D.F. closed this discussion on 25 Aug, 2012 02:40 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac