Mixing scriplets within droplets question? newbie question

All,
I am trying to retrieve data from a droplet and store it in csv format. For this purpose, i am planning to use a stringBuilder, iterate the data returned using for each and append this string builder. At the end of the code i am planning to use scriplet to read this string buffer. Below is my code.
First issue is : As soon as i add scriplet within <dsp:getvalueof> tag my page stops working
Second issue : So you think scriplet at the end of code is correct?
Thanks in advance
Any help on topic will be appreciated.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib uri="dsp" prefix="dsp" %>
<%@ page import="java.io.FileInputStream" %>
<%@ page import="java.io.BufferedInputStream" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.List" %>
<%@ page import="java.net.URLConnection" %>
<%@ page import="java.io.BufferedOutputStream" %>
<%@ page import="java.util.zip.ZipOutputStream" %>
<%@ page import="java.io.FileOutputStream" %>
<%@ page import="java.util.zip.ZipEntry" %>
<dsp:page>
<dsp:importbean bean="/xyz/droplet/NikeProductsDroplet"/>
<dsp:importbean bean="/xyz/core/util/ProductCatalogUrlBuilderDroplet"/>
<%
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=temp.csv");
String testVar ="" ;
StringBuffer writer = new StringBuffer();
     writer.append("DisplayName");
     writer.append('\n');
%>
     <dsp:droplet name="ABCProductsDroplet">
          <dsp:oparam name="output">
DisplayName, Part Number, Vendor Name, URL
               <dsp:droplet name="/atg/dynamo/droplet/ForEach">
                    <dsp:param name="array" param="allProducts" />
                    <dsp:oparam name="output">
<dsp:getvalueof id="displayNameTest" param="element.displayName" idtype="java.lang.String">
<%
testVar = displayNameTest;
writer.append(testVar);
writer.append('\n');
%>
</dsp:getvalueof>
</dsp:oparam>
</dsp:droplet>
</dsp:oparam>
</dsp:droplet>
<%
     ServletOutputStream out = response.getOutputStream();
     InputStream in = new ByteArrayInputStream(writer.toString().getBytes("UTF-8"));
byte[] outputByte = new byte[4096];
          while(in.read(outputByte, 0, 4096) != -1)
               out.write(outputByte, 0, 4096);
          in.close();
          out.flush();
          out.close();
     %>
</dsp:page>

First issue is : As soon as i add scriplet within <dsp:getvalueof> tag my page stops working
You must be getting some error in console.Please post that error.
directly use :
<dsp:getvalueof id="displayNameTest" param="element.displayName" idtype="java.lang.String">
<%
writer.append(displayNameTest);
writer.append('\n');
%>
</dsp:getvalueof>

Similar Messages

  • To mix or not to mix that is the question

    Hi,
    Whilst doing some research on JSP's I came across this line:
    "For more complicated HTML, using the out variable all the time loses some of the advantages of JSP programming. It is simpler to mix scriptlets and HTML. " (http://www.jsptut.com/Mixing.jsp)
    Is this true? Is it more effective to mix the code like this?
    I ask because I am about to embark on a new project making use of Java and JSP's and my previous web development experience is in PHP where I have almost religiously avoided this kind of code mixing. It has always looked messy to me.
    So, my question is this - is there any advantage or disadvantage to mixing code or not ixing code or does it come down to simple personal preference?
    Thanks in advance
    Nathan

    This is quite the discussion now. I must admit I'm learning a lot which is great but I also feel I should have some input into the discussion.
    As I indicated at the start I am not a fan of mixing code and, if you read the original link, you will see that the alternative is to use the JSP to write the output using out.println This is similar, if not identical to using echo in PHP.
    I am currently researching techniques as I have a large project about to kick off and I need to ensure I get the best possible solution. I intend to use JSP's that simply call Java classes and methods that are in a separate business layer. This should result in clean and easy JSP files that may indeed use EL (now I know about it).
    So, my 2c on the original question now is that I won't be mixing code simply to ensure legibility when maintaining the code in the future.
    As for the point raised regarding the abuse of technology yes all technology can be abused and every programming language can be used to develop crap code. I was really seeking some advice on what is considered good and bad practice in this arena so that I don't develop a company standard based solely on my own personal preference.
    Thanks again for the help and for the enjoyable discussion
    Nathan

  • Adobe droplet question, involving Place command and filenames

    Suppose I have two files called, (a) "background.tif" and (b) "Image001.tif".
    Background.tif is a simple black layer, sized to 1500 x 1000 px.  Image001.tif may be cropped to any size.
    I want to do the following in a droplet:
        1. Place (File/Place) "Image001.tif" in "background.tif", knowing it'll be centered and resized as needed automatically.
        2. Save the new file for the web as "Image001.jpg",
        3. close both files without saving (I only need the resulting JPG).
    My goal - I have several hundred files that all need web-ready JPGs created with a standard size black background, so that they'll fit a web gallery that can only handle a fixed set of dimensions.
    Questions:
    1. Is this even possible via automation?
    2. If so, how do I ensure that the JPG that gets created has the same name as the source image file; i.e. "image001.jpg", and then "image002.jpg", etc.?
    3. is there a better way to create the end result, rather than using the place command; i.e. doing this with the original image file instead (thus solving the filenaming question)?
    Running PS CS6 on Win7/64.
    Many thanks!
    Jerry

    Hi csuebele,
    The only requirement is that the final result is 1500 x 1000 px.  The black is used to fill in the sides/tops as necessary.  Since this is to be automated, I need each new file to have a unique name of course (otherwise succeeding files will overwrite their predecessor).
    For example, say I have a file called image001.tif that is cropped to 2400w x 3000h px. I need this to fit a container that's 1500 x 1000 px, with black filling this out.
    Manually I would
    1. Open a black TIFF that's already 1500x1000.
    2. Place the 2400x3000 px image in the black tiff.
    3.  PS then resizes and centers the image to fit, while preserving the aspect ratio. 
    4. Thus the image is now sized to be 800w x 1000h px , with black filling the sides equally; i.e. 750 px of black on either side.
    5. I then save that "new" version of the black file for the web, and then close w/o saving.
    6. End result is a 1500x1000 file called image001.JPG.
    Please see attached for 2 examples:
    Example of a portrait image:
    Example of a landscape image:

  • Images with dynamic labels within: initial question

    Hi everybody,
    My question is simple (I am very new to Java2d); I want to open a image (JPG, BMP...), draw some simple text strings and messages on it and return it;
    could anybody recomend me a tutorial, a example or some documentation for doing this in a simple way?
    TIA,
    Daniel

    Hi.
    Try something like this:
    BufferedImage bufferedImage = ImageIO.read(new File("source.jpg"));
    Graphics2D graphics = (Graphics2D) bufferedImage.createGraphics();
    graphics.drawString("Hello in Image", 0, 0);
    return bufferedImage;For more primitives, check the docs of Graphics2D and Graphics classes.
    Hope this helps.

  • How to stop the mixed-content Yes/No question every time you log in or change screens.

    Since the new VZW forum format when I log in or change screens I have been asked if I want to accept content that was not sent encrypted (HTTPS:\).  See attached photo to see what I mean.
    Speaking for myself, I found this very annoying so here is how to stop it if you are using Windows Internet Explorer.
    Bring up Windows Internet Explorer.  I use IE8 and it fixed mine.
    Then go to TOOLS>Internet Options and Select the Security Tab.  Then Click the Custom Level button.  Next go down through the list in the Miscellaneous Section and change "Display Mixed Content" to ENABLE.
    Hope this makes your day a bit brighter, it did mime!
    JerryF
    If you want to see more about this you can look here.
    http://blogs.msdn.com/b/askie/archive/2009/05/14/mixed-content-and-internet-explorer-8-0.aspx

    jco23,
    Go back and again check to see that it is ENABLED.
    I say this because the first time I "tried" to enable it, it didn't enable it.  I tried again and discovered that I did NOT do the proper exit procedure when closing (leaving) the miscellaneous list after I changed it to enabled.  Oh dopey me!!!
    The second time it worked.
    JerryF

  • Tiles Within JSP Question

    I have a JSP that has this line...
    <img src="<tiles:getAsString name='imgName'/>" />
    I get "weird" results however, when I call this JSP. The controller class that I had called (that calls this JSP) gets called a second time for some odd reason. If I put in a hard-coded string inside src then I don't have this problem. It seems like a very bizaare thing to me but that's what's happening. Note that if I put the line <tiles:getAsString name="imgName"/> outside of the src attribute then I don't have this problem either.
    Any help would be GREATLY appreciated.

    Thanks, that thread was informative. I thought it might help to use a base tag to set the url for the page, but I'm still baffled as to how the getServletContext().getRequestDispatcher() works and why this:
    <p>getServletContext().getRequestDispatcher("/welcome.jsp")
    <p>(from within the servlet at /WEB-INF/classes/Login.class) displays the welcome.jsp page in the browser but you look into the location bar and you see the servlet path "/servlet/Login".
    <p> thanks.

  • Mixing Down Multiple Tracks - Question

    Hi.
    Is it possible to mix down 2 or more tracks into 1 single track?
    I'm doing some soundtrack work, working on the multi-track editor to a video I imported. I have a constant background ambiance that I made using the multi-track editor and the apple loops.
    Is there a way I can mix the 3+ tracks that make up this ambiance down into 1 single track? Thus giving me less tracks to worry about (and less clutter) when editing additional foley sound effects etc.. over the ambiance?
    Any help would be appreciated

    Export your mix. In the After Export drop-down you should find *Add to New Tracks in session* (or something like that)
    !http://rdiv.com/screenshots/STP_exportOption.jpg!

  • Menu Widget within Template Question

    I've placed a simple Spry Horizontal Menu bar widget within a div called "header." This menu bar has four main list items, and each list item has four sub-items. I have another div called "mainContent." I save this page as a template. I make a sample page using that template, and the page works as expected. So far, so good.
    Now, I go into the template file, into the menu bar widget, and I add a fifth sub-item to one of the main list items, using the properties panel. I save the file, and DW asks if I want to update the page I've created based upon this template. I say yes, and it appears to make the update.
    Now, however, when I test the page in the browser (FF, Safari, Opera, doesn't matter), the newly-added menu item does not appear. I've tried clearing the browser cache, closing and reopening the browser -- nada.
    Am I missing something, or is a Spry widget not able to be used (as in, modified and updated) within a template?
    Any help is gratefully appreciated.

    Unfortunately you cannot add drop shadows to text in Muse.
    You could create the text in Photoshop and import it in, using the "Place Photoshop button" under the file menu. (you would create the, normal, hover, active states in Photoshop layers)

  • Tables within Tables Question

    Hello!
    I have been searching through the forums and can't seem to find an answer. Maybe it's just that I am not sure what I am looking for. I am trying to build a table  that has a 1 large picture next to 6 small ones. I figured that I could be a table that is 3 rows by 4 columns, merge all cells in the first column, and use the top two remaining rows for the pictures. It works fine in Chrome:
    But in Explorer, it looks like this:
    Can anyone point me in the right direction?
    Thank you!

    I strongly suggest taking the time to learn about cascading style sheets and how you can use css to control <div> tags to layout your page over attempting a table based layout. There are many places online to find tutorials about css, one of my favorite references is http://www.w3schools.com they also have a walk through tutorial for css that will help you on your way, away from nested table layouts.
    That being said.
    You can do it with tables, but you're going about it the wrong way. Start out with a 2 colum 1 row table. In the left cell, place your large image. In the right cell, place another table with 3 colums and 2 rows. Place your small images in those cells.

  • Subsription - Calls within US question

    Can I use the basic $2.99/month subscription to make calls FROM the US to other phones IN the US? The language of the terms is confusing and I don't want to start that subscription if I can't.
    Thank you.

    Yes you can. You can call from your computer to any phone in the US or Canada. You can call from your mobile with a skype app while you are on wifi.
    If you found a post useful, please give Kudos. If it helped to fix your issue, mark it as a solution to help others.
    Thank You!

  • JPEG Files in Premiere Getting Mixed Up Within a Project

    JPEG files loaded into my project are getting mixed up.  It's like Premiere can't tell the loaded files apart. That is, I load several JPEGs in to the project, each with a different file name, put them onto the Timeline, and, later, when I click on the file name in the Project panel, several of the different files display the same image of one of the JPEGs in the Poster Frame, the Source Frame, and in the Project Sequence.   The file names remain listed in the Project panel continue to show the correct file name, but several show the same image when selected. 
    I assumed something happened when the files were Imported and were now confused in the project.  To try to fix this, I Cleared all of the bad files off the Timeline and out of the Project panel.  Changed the source file names in Windows Explorer (i.e., added an "a" to the file name) and re-Imported the files into Premiere.  It seemed to work, but a little while later, some of the same files, plus some newly Imported files, all turned to the same image again.  I again repeated the Clearing process for the bad files, changed the source file names once again in Windows Explorer, changed the Folder name in Explorer, and again re-Imported the files into Premiere.  Again, after a while several of the files all had changed to the same image on the Timeline, the Poster Frame, and the Source Frame.
    It's like the program has somehow mixed these files up and, whatever caused the mix up, remains persistent even with files that have been renamed.
    This happens to approximately 20 JPEGs out of perhaps 70 JPEGs in the Project.  It has not happened on any previous projects.
    I can't tell if my Premiere (5.0.3) has become corrupted somehow or if this error is limited to this one Project.  Is there a way I can transfer my work into a new project (I really don't want to have to start completely over).
    I'm fairly desperate.  Thanks!
    --Dave

    See this thread for a workaround:
    http://forums.adobe.com/message/3684577#3684577
    This bug has been fixed in Premiere Pro CS5.5.

  • Disable Job Action within Droplet

    I made a droplet in Compressor 4 that allows me to easily transcode HDSLR footage to ProRes for editing in FCP7. Is there a way to disable the job action script that launches QuickTime X after each video clip finishes transcoding? I can't see the checkbox anywhere in the app?

    Weird? I just created a new Droplet and that job action doesn't show up anymore. Not sure how I initially set that or if it was just an initial bug

  • 2 iphones sync on same computer & our texts get mixed up within AT&T network...

    My husband & I both have iphones (he has the iPhone 4 & I have his old iPhone 3S) that we sync on the same itunes on the same computer. Recently, our text messages have been mixed up but only with one other of our friends. If she texts either one of us, we don't receive her texts even though they show up as "Delivered" in iMessage. If either one of us text her, it shows up with my husband's name on it & since this started happening, she has old threads of texts from him & a new thread that says it's from him but they're actually coming from my phone. sometimes my texts to her show up as my name. but the only way she can get a text to either of us is by responding to that one separate thread & it randomly will go through to my husband & he can respond. sometimes it comes to me & i can respond. but we cannot start new text threads & she cannot send any text messages to my number directly. anyone else encounter this? AT&T says it's not their system. She has never synced with our computer & she is the only friend experiencing this. any ideas?

    nope. we used to be, but i've got my own now but have had my own for almost a year. this only started happening about 4 weeks ago. both of our phones were updated long before then when this last update came out, so nothing has changed that we can find to have sparked this.

  • Nested styles within TOC - a newbie

    Hi, I wonder if someone can help with a TOC query. It will involve nested character styles which I've not really got my head around
    Currently there are two paragraph styles in the book to appear in the TOC in their own styles (so four paragraph styles in total - Chapter Number, Chapter Name, Chapter Number TOC and Chapter Name TOC).
    They currently generate in their simplest form in the TOC as:
    Chapter 1
    An introduction to your new home ................8
    I simply want the chapter name to appear on the same line.
    Chapter 1 An introduction to your new home ................8
    Thanks for any help anyone.

    Peter Spier wrote:
    Peter G,
    I don't do XML, but I think the answer is basically the same as initially outlined. If it's one paragraph with some sort of magic line break character, that character is going to be carried into the TOC and create a line break there as well, and if it's two paragraphs sepatated by a magic separator, it's going to remain two paragraphs. Break characters don't just disappear on their because we decide we don't want to see them -- they have to be deleted, and styles cannot add or remove text, only change the formatting.
    The  neat thing about the No Break style (which never occurred to me before this morning), is precisly that it doesn't depend on any break characters to work, only the supposition that the second part of the paragraph will be too long to fit unbroken on the same line as the first part, and that it will fit on a new line. ID simply breaks the text at that point because it has no better choice. This is not, unfortunately, guaranteed to work for all paragraphs as it depends on column widths and text length to work in combination to force the break.
    The No Break approach is a good solution if the TOC text frame and paragraph properties can be made to wrap at the allowed break position.
    I was trying to find a counterpart to FrameMaker's run-in paragraph feature, but as you verified, it's not possible. FYI, here's how it looks in FM:
    The source document uses ChapNum paragraph format (aka "ID paragraph style" for "Chapter number 1:" which is all in the autonumber part of the paragraph. The ChapTitl paragraph format is used for the "Chapter title" text.
    As in ID, the two paragraph formats/styles are designated to be extracted by the TOC process. FM's TOCs are always generated as independent files. In the TOC document, ChapNum format/style becomes ChapNumTOC, and ChapTitle format/style becomes ChapTitleTOC. The *TOC styles can be styled differently from their source paragraphs. So, ChapNumTOC is given the run-in property which allows the next paragraph in the document - here it's the ChapTitlTOC paragraph with "Chapter Title" text - to follow it on the same line. However, you can see the green pilcrow at the end of the ChapNumTOC paragraph, which identifies it as a true paragraph, that happens to lack the property that starts it on a new line. Once the TOC's formatted properly, every subsequent TOC process is completely "hands off," i.e., no manual touch up needed, nothing to forget. This is why I keep submitting an enhancement request for this ability, and also encourage others.
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • Setting XML based exam to where there are two correct answers in a question

    I have an exam which pulls in questions from an XML file and to indicate what the correct answer is you would indicate in the XML as such:
    PROBLEM id="1">
                    <QUESTION>What is the State Capital of California:</QUESTION>
                    <CHOICE letter="a">San Fransisco.</CHOICE>
                    <CHOICE letter="b">San Diego.</CHOICE>
                    <CHOICE letter="c">Los Angelas.</CHOICE>
                    <CHOICE letter="d" correct="true">Sacremento.</CHOICE>
                </PROBLEM>
    There is one question, that is structured so there are two right answers, but when I add correct="true" to both answers I want as right only one is calculated correctly in the scoring. I thinking I need to make an adjustment in the code that pulls in the XML, but not sure where. Hoping someone can help.
    Here is the AS code.
    package exam {
        import flash.net.* //to create URLRequest and load XML file
        import flash.events.* //for Load events
        //import flash.display.* //for testing purposes - remove when testing complete
        //This class downloads the XML document, and then inserts info into arrays and variables.
        //Also provides text of questions and correct answers when requested.
        internal class XaMLDiplomat extends EventDispatcher {
            //VARIABLES:
            //for loaded XML doc
            private var myXML:XML;
            //for loading in XML
            private var examLoader:URLLoader;
            private var numQstns:Number; //count of total questions in a section
            private var sectStart:Number;
            //contains exam questions - ALL ARRAYS ARE ZERO RELATIVE -> actual question numbers = array index + 1
            private var questions:Array;
            //contain associated answer choices
            private var choiceA:Array;
            private var choiceB:Array;
            private var choiceC:Array;
            private var choiceD:Array;
            private var choiceE:Array;
            private var choiceF:Array;
            //array of the correct answers
            private var answers:Array;
            //use custom Mixer class to randomize order
            private var myMixer:Mixer;
            private var isRandom:Boolean;
            //CONSTRUCTOR
            public function XaMLDiplomat () { //NEED TO ADD ARGUMENTS (docLocation)
                //create URLRequest from argument
                var examSite:URLRequest = new URLRequest("protected/exam.xml");
                //create a loader for the XML
                examLoader = new URLLoader();
                //add listener for load completion
                examLoader.addEventListener(Event.COMPLETE, fullyLoaded);
                examLoader.load(examSite);
                //var ugly:Mixer = new Mixer(25);
            //Load listener - creates XML object, and checks it for multiple sections. If multiple, it asks users
            //which section they want - FIRST it needs to check database for any completed sections.
            //If single, it goes ahead and starts array creation for first (& only) section
            private function fullyLoaded (e:Event):void {
                myXML = new XML(examLoader.data);
                //myXML.prettyPrinting = false;
                //still need to pull out SYSTEM data and pass it along...
                var system:XMLList = myXML..SYSTEM;
                var sysObj:Object = new Object();
                sysObj.examTitle = system.TITLE.toString();
                sysObj.totalMin = system.MINUTES.toString();
                sysObj.retakePW = system.RETAKEPW.toString();
                var numSections:Number = myXML..SECTION.length();
                if (numSections == 1) {
                    generateArrays(1);
                dispatchEvent(new MultiSectEvent(MultiSectEvent.SECTIONS, numSections, sysObj));
            //Assigns arrays to instance variables for the selected section
            internal function generateArrays (sectn:Number):void {
                var whichSection:XMLList = myXML..SECTION.(@id == String(sectn));
                var probList:XMLList = whichSection.PROBLEM;
                numQstns = probList.length();
                sectStart = Number(probList[0].@id);
                questions = new Array();
                choiceA = new Array();
                choiceB = new Array();
                choiceC = new Array();
                choiceD = new Array();
                choiceE = new Array();
                choiceF = new Array();
                answers = new Array();
                for (var i:Number=0; i<numQstns; i++) {
                    var curProb:XMLList = probList.(@id == String(i+1));
                    if (curProb.QUESTION.hasSimpleContent()) {
                        questions[i] = curProb.QUESTION.toString();
                    }else {
                        //trace(curProb.QUESTION.toXMLString());
                        questions[i] = dropTags(curProb.QUESTION[0]);
                    choiceA[i] = curProb.CHOICE.(@letter == "a").toString();
                    choiceB[i] = curProb.CHOICE.(@letter == "b").toString();
                    choiceC[i] = curProb.CHOICE.(@letter == "c").toString();
                    choiceD[i] = curProb.CHOICE.(@letter == "d").toString();
                    choiceE[i] = curProb.CHOICE.(@letter == "e").toString();
                    choiceF[i] = curProb.CHOICE.(@letter == "f").toString();
                    answers[i] = curProb.CHOICE.(hasOwnProperty("@correct") && @correct == "true")[email protected]();
                //randomizing test
                //var makeRandom:Boolean;
                //system.RANDOM.toString() ==  'true' ? makeRandom = true : makeRandom = false;
                //myMixer = new Mixer(numQstns,makeRandom);
                trace("Question: "+questions[3]);
                trace("a: "+choiceA[3]);
                trace("b: "+choiceB[3]);
                trace("c: "+choiceC[3]);
                trace("d: "+choiceD[3]);
                trace("\r\n answer: "+answers[3]); */
            //method for external classes to acquire text of current exam question
            internal function getQuestion (qnum:Number):Object {
                var returnObj:Object = new Object();
                var randomQ:Number = myMixer.getRandomNumber(qnum-1);
                returnObj.q = questions[randomQ];
                returnObj.ca = choiceA[randomQ];
                returnObj.cb = choiceB[randomQ];
                returnObj.cc = choiceC[randomQ];
                returnObj.cd = choiceD[randomQ];
                returnObj.ce = choiceE[randomQ];
                returnObj.cf = choiceF[randomQ];
                returnObj.num = qnum;
                //trace(randomQ);
                return returnObj;
            private function dropTags (txt:XML):String {
                var txtString:String = "";
                for each (var child:XML in txt.*) {
                    if (child.nodeKind == "text") {
                        txtString += child.toString();
                    }else {
                        txtString += " " + child.toXMLString();
                //trace(txtString);
                return txtString;
            private function dropTags (txt:String):String {
                var sliceStart:Number = txt.indexOf(">");
                var sliceStop:Number = txt.lastIndexOf("<");
                return txt.slice((sliceStart+1), sliceStop);
            internal function getAnswer (num:Number):String {
                return answers[num];
            internal function getQCount ():Number {
                return numQstns;
            internal function getSectStart():Number {
                return sectStart;
            internal function getRealNum (num:Number):Number {
                return myMixer.getRandomNumber(num-1);

    this may or may not be the probel, but as it stands right now, when you select and anser it becomes hi-lighted and when you click off and select another answer the previous answer is deselected and the current answer is hi-lighted. I need to allow for multiple selections. This code is what is doing to current select/de-select functionality.
    package exam {
        import flash.display.*;
        import flash.events.*;
        import flash.text.*;
        //This class displays the current question, and contains the Choices for the question
        public class QMachine extends Sprite {
            //VARIABLES
            private var QObject:Object; //object from XaMLDiplomat, containing necessary text
            private var limit:Number;
            private var QNumTxt:TextField;
            private var QTxt:TextField;
            private var txtStyle:StyleSheet;
            private var choiceA:Choice;
            private var choiceB:Choice;
            private var choiceC:Choice;
            private var choiceD:Choice;
            private var choiceE:Choice;
            private var choiceF:Choice;
            //CONSTRUCTOR
            public function QMachine (hite:Number) {
                limit = hite;
                var style:Object = new Object();
                style.fontFamily = "Arial";
                //style.fontWeight = "bold";
                style.fontSize = "16";
                style.color = "#333333";
                txtStyle = new StyleSheet();
                txtStyle.setStyle("p",style);
                QNumTxt = new TextField();
                QNumTxt.styleSheet = txtStyle;
                //QNumTxt.embedFonts = true;
                QNumTxt.htmlText = "<p>1) </p>";
                QNumTxt.autoSize = TextFieldAutoSize.RIGHT;
                QNumTxt.x = 10;
                QNumTxt.mouseEnabled = false;
                QTxt = new TextField();
                QTxt.styleSheet = txtStyle;
                //QTxt.embedFonts = true;
                QTxt.width = 300;
                QTxt.multiline = true;
                QTxt.wordWrap = true;
                QTxt.autoSize = TextFieldAutoSize.LEFT;
                QTxt.htmlText = "<p>Question 1</p>";
                QTxt.x = 35;
                QTxt.mouseEnabled = false;
                addChild(QNumTxt);
                addChild(QTxt);
                choiceA = new Choice("a");
                choiceA.x = 350;
                addChild(choiceA);
                choiceB = new Choice("b");
                choiceB.x = 350;
                addChild(choiceB);
                choiceC = new Choice("c");
                choiceC.x = 350;
                addChild(choiceC);
                choiceD = new Choice("d");
                choiceD.x = 350;
                addChild(choiceD);
                choiceE = new Choice("e");
                choiceE.x = 350;
                addChild(choiceE);
                choiceF = new Choice("f");
                choiceF.x = 350;
                addChild(choiceF);
                addEventListener(MouseEvent.MOUSE_UP, selectResponse, true);
            internal function newQuestion (obj:Object, prior:String = ""):void {
                //trace(obj.num);
                QNumTxt.htmlText = "<p>"+ obj.num + ".</p>";
                QTxt.htmlText = "<p>"+ obj.q + "</p>";
                choiceA.deselect();
                choiceB.deselect();
                choiceC.deselect();
                choiceD.deselect();
                choiceE.deselect();
                choiceF.deselect();
                choiceA.resetSize();
                choiceB.resetSize();
                choiceC.resetSize();
                choiceD.resetSize();
                choiceE.resetSize();
                choiceF.resetSize();
                choiceA.changeTxt(obj.ca);
                choiceB.changeTxt(obj.cb);
                choiceB.y = choiceA.height + 5;
                if (obj.cc == undefined || String(obj.cc) == "") {
                    choiceC.visible = false;
                }else {
                    choiceC.changeTxt(obj.cc);
                    choiceC.y = choiceB.y + choiceB.height + 5;
                    choiceC.visible = true;
                if (obj.cd == undefined || String(obj.cd) == "") {
                    choiceD.visible = false;
                }else {
                    choiceD.changeTxt(obj.cd);
                    choiceD.y = choiceC.y + choiceC.height + 5;
                    choiceD.visible = true;
                if (obj.ce == undefined || String(obj.ce) == "") {
                    choiceE.visible = false;
                }else {
                    choiceE.changeTxt(obj.ce);
                    choiceE.y = choiceD.y + choiceD.height + 5;
                    choiceE.visible = true;
                if (obj.cf == undefined || String(obj.cf) == "") {
                    choiceF.visible = false;
                }else {
                    choiceF.changeTxt(obj.cf);
                    choiceF.y = choiceE.y + choiceE.height + 5;
                    choiceF.visible = true;
                var curHite:Number;
                if (choiceF.visible) {
                    curHite = choiceF.y + choiceF.height + 5;
                }else if (choiceE.visible) {
                    curHite = choiceE.y + choiceE.height + 5;
                }else if (choiceD.visible) {
                    curHite = choiceD.y + choiceD.height + 5;
                }else {
                    curHite = choiceC.y + choiceC.height + 5;
                if (curHite > (limit-150)) {
                    shrinkText();
                if (prior != "") {
                    if (prior == "a") {
                        choiceA.nowSelected();
                    }else if (prior == "b") {
                        choiceB.nowSelected();
                    }else if (prior == "c") {
                        choiceC.nowSelected();
                    }else if (prior == "d") {
                        choiceD.nowSelected();
                    }else if (prior == "e") {
                        choiceE.nowSelected();
                    }else if (prior == "f") {
                        choiceF.nowSelected();
            private function shrinkText() {
                choiceA.dropSize();
                choiceB.dropSize();
                choiceC.dropSize();
                choiceD.dropSize();
                choiceE.dropSize();
                choiceF.dropSize();
                choiceB.y = choiceA.y + choiceA.height + 5;
                choiceC.y = choiceB.y + choiceB.height + 5;
                choiceD.y = choiceC.y + choiceC.height + 5;
                choiceE.y = choiceD.y + choiceD.height + 5;
                choiceF.y = choiceE.y + choiceE.height + 5;
                var curHite:Number = 0;
                if (choiceF.visible) {
                    curHite = choiceF.y + choiceF.height + 5;
                }else if (choiceE.visible) {
                    curHite = choiceE.y + choiceE.height + 5;
                }else if (choiceD.visible) {
                    curHite = choiceD.y + choiceD.height + 5;
                }else {
                    curHite = choiceC.y + choiceC.height + 5;
                if (curHite > (limit-150)) {
                    shrinkText();
            private function selectResponse (e:MouseEvent):void {
                choiceA.deselect();
                choiceB.deselect();
                choiceC.deselect();
                choiceD.deselect();
                choiceE.deselect();
                choiceF.deselect();
                var letter:String = e.target.parent.getLetter();
                dispatchEvent(new ResponseEvent(ResponseEvent.SELECTION, letter));
            internal function setPriorResponse() {
                choiceA.deselect();
                choiceB.deselect();
                choiceC.deselect();
                choiceD.deselect();
                choiceE.deselect();
                choiceF.deselect();

Maybe you are looking for