AS3: Dynamic XMLListCollection

Hi,
I am writing AIR app emulating Excel 2007.
Trying to initialize a DataGrid dataProvider, which is XMLListCollection.
Need to create something like that:
<root>
<row><A/><B/><C/>...</row>
</root>
But the number of rows and columns should be paramatrized like:
private function initDG(colNum:int, rowNum:int):void {
if (!gridData)
     gridData = new XMLListCollection();
for (var j:int=0; j < rowNum; j++) {                   
    for (var i:int=0; i < colNum; i++) {                  
          // WHAT should be here to initialize every element of XMLListCollection ???         
         //gridData.addItem({<row><A/><B/><C/><D/><E/></row>}); // that obviously doesn't work  
grid.dataProvider = dataGrid;
this.addChild(grid);         
TIA,
Oleg.

To answer my question the initialization loop should be something like that:
for (var j:int=0; j < rowNum; j++) {
      rowXML = <row/>;
      for (var i:int=0; i < colNum; i++) {    // init each DG cell to "" (i.e. like: <A/>)                      
          rowXML.appendChild(new XML("<"+colNames[i]+"/>"));
     gridData.addItem(rowXML);
Thanks,
Oleg.

Similar Messages

  • How do you create a gridrow / griditem in as3 dynamicly

    Hi i have made a grid block to diplay certain colours but it makes the code look nasty.
    this is a breif look at the code
    <mx:Grid id="mxGrdColour" height="100%" horizontalGap="2" verticalGap="2" styleName="mxGrdStyleColour" left="1" right="3" top="1" bottom="3" >
                                        <mx:GridRow width="100%" height="100%">
                                            <mx:GridItem id="grdColour_GI0" width="100%" height="100%" click="mxGrdColourClicked(0)" />
                                            <mx:GridItem id="grdColour_GI1" width="100%" height="100%" click="mxGrdColourClicked(1)" />
                                            <mx:GridItem id="grdColour_GI2" width="100%" height="100%" click="mxGrdColourClicked(2)" />
                                            <mx:GridItem id="grdColour_GI3" width="100%" height="100%" click="mxGrdColourClicked(3)" />
                                            <mx:GridItem id="grdColour_GI4" width="100%" height="100%" click="mxGrdColourClicked(4)" />
                                        </mx:GridRow>
    </Grid>
    if it possiable to create this structure dynamicly in as3 so i can have it randon lengths.
    any help would be great or examples
    Thanks
    Paul

    It woiuld look even nastier in AS. Here is just initializing the Grid n AS:
            mxGrdColour.percentHeight = 100;
            mxGrdColour.setStyle("horizontalGap", 2);
            mxGrdColour.setStyle("verticalGap" = 2);
            mxGrdColour.styleName = "mxGrdStyleColour"
            mxGrdColour.setStyle("left", 1);
            mxGrdColour.setStyle("right" = 3);
            mxGrdColour.setStyle("top", 1);
            mxGrdColour.setStyle("bottom"3);
    Better off sticking with MXML, although you could put this in an MXML component to keep the main app less cluttered:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Grid xmlns:mx="http://www.adobe.com/2006/mxml" height="100%"
      horizontalGap="2" verticalGap="2" styleName="mxGrdStyleColour"
      left="1" right="3" top="1" bottom="3" >
      <mx:GridRow width="100%" height="100%">
        <mx:GridItem id="grdColour_GI0" width="100%" height="100%" click="mxGrdColourClicked(0)" />
        <mx:GridItem id="grdColour_GI1" width="100%" height="100%" click="mxGrdColourClicked(1)" />
        <mx:GridItem id="grdColour_GI2" width="100%" height="100%" click="mxGrdColourClicked(2)" />
        <mx:GridItem id="grdColour_GI3" width="100%" height="100%" click="mxGrdColourClicked(3)" />
        <mx:GridItem id="grdColour_GI4" width="100%" height="100%" click="mxGrdColourClicked(4)" />
      </mx:GridRow>
    </Grid>

  • AS3 - dynamic class names with *new* operator

    I'm using AcrtionScript 3 and Adobe Flash 9 Public Alpha.
    I have 50 movie clips in the Library that use Linkage to set
    the Class name to: Img1, Img2, Img3, ..., Img50.
    I have a parent class named RandImg. I want the constructor
    for RandImg to randomly select one of the 50 movie clips from the
    Library and display it. I could get this working by generating a
    random number, and then writing a really huge switch statement to
    associate each possible random number with its respective Library
    Movie Clip Class name, but I would much rather do this with a
    dynamic/variable class name based on the random number, such as:
    var nImgChoice:Number = Math.floor( Math.random( ) * 50 ) +
    1;
    var mcImg:MovieClip = new [ "Img"+String(nImgChoice) ] ( );
    addChild( mcImg );
    Note that this used to be possible in AS 2 by doing the
    following:
    this.attachMovie( "Img"+String(nImgChoice) , "mcImg",
    this.getNextHighestDepth());
    Suggestions?
    Thanks,
    ~JC

    import flash.display.DisplayObject;
    import flash.display.Sprite;
    import flash.utils.getDefinitionByName;
    var nImgChoice:Number = Math.floor( Math.random( ) * 50 ) +
    1;
    var ClassReference:Class =
    getDefinitionByName("Img"+String(nImgChoice) ) as
    Class;
    var instance:Object = new ClassReference();
    addChild(DisplayObject(instance));

  • AS3 dynamic font embedding bug

    Hi all,
    Is there a known bug for the following case?
    Case:
    A project I'm working on doesn't seem to handle font embedding correctly when the font is added dynamically using actionscript. When I test my movie it does not display the embedded font at all. Curious about this is, that when I create an empty project using the same code and then embed the font and test the movie it displays the font without any problem.
    Sometimes a reboot of the machine I'm working on will suffice to make the embedding work again, but sometimes is not all the time. So I was wondering if there was a memory related bug that causes this behavior. If so, is there any sight on a solution for this bug? It's more than annoying to reboot eight times a day, just to test a movie.
    How did I embed the font:
    1. Create a "New Font" in the Library, set the properties and give it a classname.
    2. Using actionscript to embed the font in a dynamically generated TextField.
    package{
    import flash.display.MovieClip;
    import flash.display.text.Font;
    import flash.display.text.TextFormat;
    import flash.display.text.TextField;
    public class MyClass extends MovieClip{
    var myFont:Font;
    var myTextFormat:TextFormat;
    var myTextField:TextField;
    public function MyClass():void{
    myFont = new Font1();
    myTextFormat = new TextFormat();
    myTextFormat.font = myFont.fontName;
    myTextField = new TextField();
    myTextField.defaultTextFormat = myTextFormat;
    myTextField.embedFonts = true;
    myTextField.text = "Lorem Ipsum...";
    addChild(myTextField);
    Cheers!
    Do

    I don't have Flash IDE on this machine so I cannot say for sure but try to register font:
    public function MyClass():void {
         Font.registerFont(Font1);
         myFont = new Font1();
         // the rest...

  • How can i set the dynamic text box to show variable value?

    In AS2, I can make a dynamic text box set a var name, when i
    use button set/change the var value, this textbox can show the
    value also.
    but In AS3, dynamic text box can't add var name. than how can
    i do it now?

    Set an instance name for the dynamic textfield. Then, to
    populate the textfield with the value of a variable, use:
    textFieldInstanceName.text = variableName

  • How to stream images stored in an external server in to a Flash Web Site?

    I would like to be able to bring in external images in a banner like in a slideshow, but not sure how to do it. I have a bunch of small images that I would like it to go through, and my current banner has all the images in the swf and the swf file is huge. Is there a way to import external images from a folder on the server? Where can I go to learn how to do this? Thanks....
    To get an idea of what I'm talking about, here's the banner on our site...
    http://www.wenatcheekennelclub.com/images/header.swf

    Your best bet for this would be to search Google using search terms like "AS3 slideshow tutorial" or "AS3 dynamic slideshow turoial".  THis assumes you are designing an AS3 file.  If not, substitiute AS2 for AS3 in the terms.
    In AS3, one of the main classes used for loading external images is the Loader class. SO becoming familiar with that will be a necessary part of the learning.  But that is not all since you want to have controls for displaying the images.
    One thing I noticed with the banner you show, the images would not seem to need to be any "huge" burden as far as file goes.  You should optimize all images before you import them into the file.
    Still, having the images loading from an external supply will be better because then you can change the images as you wish without having to edit the Flash file.  To realize this capability you should include "XML" with the rest of the search terms previously identified.

  • Flash Fonts

    Hi,
    I need small help. Is it possible to load mathemetics formula in flash as3 dynamically.
    example : a2 + b2 = 2ab
                   infinity
                   mathametical symbol
    Thanks

    Hi, thanks , i google i did not find the solution. could you help me.I have small flash component 300 w and 300 height, in that flash movie i dynamically create movieclip.however the dynamic movieclip more than 10 the height will increase. so i need to increase the stage size, and automatically resize to the div tag in html also.     

  • Dynamic Photo Gallery in Flash using AS3.0 and XML, but it doesn't work and missed up my app.

    Hi,
    I am creating an iPad app using AS3. The app contains three sections.
    One of those sections (chocolate sources)contains Dynamic Photo Gallery using XML. The photos, thumbnails, and text in this section are loaded from XML.
    I faced may issue when I tried to run this app:
    The gallery photos didn't show up
    The thumbnails (buttons to navigate the photo gallery) didn't show up at all. (The thumbnails should show up under the photo gallery box.)
    The text doesn't show up (the text should be in every photo as describtion)
    I want to include Swipe in the photo gallery, how can I do that?
    When I click on "Chocolate Sources" button, the photo gallery appears in every section, here are print screens describe what I mean:
    The photo gallery covers the home screen too.
    Here is my XML:
    <?xml version="1.0" encoding="utf-8"?>
    <sources>
              <section>
                        <details>
                                            Cocoa tree exists in the tropics area, such as Central and South America.
                                  </details>
                                            <image>
                                                      <url>coca1.jpg</url>
                                                      </image>
                                                      </section>
              <section>
                        <details>
                        Cocoa is supplied in many countries such as Indonesia, Ghana, Brazil, Ecuador and Cameroon.
                        </details>
                                  <image>
                                  <url>coca2.jpg</url>
                                  </image>
                                            </section>
              <section>
                                  <details>
                                  Dark chocolate helps to relax and reduce the stress and blood pressure because it has antioxidants elements, which helps in vasodilatory process.
                                  </details>
                                            <image>
                                            <url>coca3.jpg</url>
                                                      </image>
                                                                </section>
              <section>
                        <details>
                        Chocolate provides energy and hyperactive sometimes because it contains high level of caffeine and sugar.
                        </details>
                                  <image>
                                  <url>coca4.jpg</url>
                                            </image>
                                                      </section>
              <section>
                        <details>
                        Chocolate could be mixed with many different flavors, such as mint, strawberry, orange, banana, vanilla, hazelnut, almond, coconut, and etc.
                        </details>
                                  <image>
                                  <url>coca5.jpg</url>
                                  </image>
                                            </section>
              <section>
                        <details>
                                  Chocolate is expressing of well hospitality and good time due to its lovely taste.
                                  </details>
                                            <image>
                                            <url>coca6.jpg</url>
                                                      </image>
                                                                </section>
    </sources>
    And here is my Action Script for "Chocolate Sources" section:
    stop();
    function Choco1(evt:MouseEvent): void {
              gotoAndStop('16');
    choco_btn.addEventListener(MouseEvent.CLICK,Choco1);
    function Souc1 (evt:MouseEvent): void {
              gotoAndStop ('31');
    souc_btn.addEventListener(MouseEvent.CLICK,Souc1);
    function ShopIn1 (evt:MouseEvent):void {
              gotoAndStop('46');
    shops_btn.addEventListener(MouseEvent.CLICK,ShopIn1);
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import fl.motion.MotionEvent;
    import flash.events.MouseEvent;
    import flash.sampler.NewObjectSample;
    import flash.text.TextFormat;
    var xmlLoader: URLLoader = new URLLoader (new URLRequest("sources.xml"));
    xmlLoader.addEventListener(Event.COMPLETE, finishedXmlLoader);
    var xmlFile:XML;
    var xextend:int = 10;
    var gal:galary = new galary ();
              gal.x = 85;
              gal.y = 165;
              addChild(gal);
    var txfe: TextField = new TextField ();
    txfe.x = 25;
    txfe.y = 45;
    var tformat:TextFormat = new TextFormat ();
    tformat.bold = true;
    tformat.color = 0xFFFFFF;
    tformat.size = "18";
    tformat.font = "Arial";
    txfe.defaultTextFormat = tformat;
    addChild(txfe);
    function finishedXmlLoader (e:Event): void{
              xmlFile = new XML (xmlLoader.data);
              var leng:int = xmlFile.image.length();
              txfe.text = xmlFile.image.details[0];
              for (var i:int = 0;i<leng;i++){
                        var b:thumbs = new thumbs ();
                        b.x = xextend;
                        b.y = 480;
                        b.buttonMode = true;
                        b.details = (i+1).toString();
                        addChild(b);
                        b.addEventListener(MouseEvent.MOUSE_OVER, theMosover);
                        b.addEventListener(MouseEvent.MOUSE_OUT, theMosout);
                        b.addEventListener(MouseEvent.CLICK, onMosClick);
                        var bloader:Loader = new Loader();
                        bloader.load(new URLRequest("thumbs/" + (i+1) + ".jpg"));
                        b.addChild(bloader);
                        xextend += b.width + 50;
    var loader:Loader = new Loader ();
    loader.load(new URLRequest ("pictures/coca1.jpg"));
    gal.addChild(loader);
    function theMosover(m:MotionEvent):void{
              m.currentTarget.alpha = 0.5;
    function theMosout (m:MouseEvent):void{
              m.currentTarget.alpha = 1.0;
    function onMosClick(m:MouseEvent):void{
              var loader:Loader = new Loader();
              loader.load(new URLRequest("pictures/" + m.currentTarget.details + ".jpg"));
              gal.addChild(loader);
              txfe.text = xmlFile.image.details[int(m.currentTarget.details) -1];
    I need an urgent help to fix the errors and make this section work well.
    thanks.

    try:
    txfe.text = xmlFile.section[int(m.currentTarget.details) -1].details;
    instead of
    txfe.text = xmlFile.image.[int(m.currentTarget.details) -1];
    and add your thumbs to gal, not the stage.  when you're done with the gallery, remove gal.

  • Dynamic Positioning of Objects in a Grid (rows and columns) AS3 Tutorial

    The topic of a dynamic positioning of objects in a right grid (rows and columns) comes up often so I decided to post an AS3 solution here:
    http://flashascript.wordpress.com/2010/12/25/arranging-objects-into-2d-dynamic-grid-with-a ctionscript-3/

    Hard to tell from your description but this might help:
    http://dtptools.com/product.asp?id=atid
    Bob

  • Dynamic Positioning of Objects in a Grid (rows and columns) with AS3 Tutorial

    The topic of a dynamic positioning of objects in a right grid (rows and columns) comes up often so I decided to post an AS3 solution here:
    http://flashascript.wordpress.com/2010/12/25/arranging-objects-into-2d-dynamic-grid-with-a ctionscript-3/

    Hard to tell from your description but this might help:
    http://dtptools.com/product.asp?id=atid
    Bob

  • Dynamic Text and changing Text in AS3

    I have a Dynamic Text box in my Library.  I drag it to my main stage and give it a name..it is now a movieclip. The name is 'mcAdmin'.  I added an event listener for MOUSE_OVER.  I want the text to change color, but for now I'm just trying to change the text; however, it's not displaying the change in text I want.  I do a trace, and the change is in there on the output window, but it is not displayed as such.  How can I :
    1) use AS3 to change the font color of the text
    2) use AS3 to change the text and have it display?
    function onMouseOver_txtAdmin(e:MouseEvent):void
    Mouse.cursor="button";
    //Current mcAdmin text is 'Administration'
    //I want to change the color of Administartion on Mouse_Over
    //but to test if I can get to anything, I'm just trying to change the text.
    mcAdmin.text="Hello";
    trace(mcAdmin.text);
    mcPPMB.alpha=.5;
    mcASB.alpha=.5;
    mcISO.alpha=.5;
    mcEA.alpha=.5;
    mcAdmin.alpha=1;
    mcAdmin.scaleX=1.25;
    mcAdmin.scaleY=1.25;
    Thanks.

    1st
    give the textfield a name, if it hasn't already (sounds like you put it in a movieclip).
    to change the text set the text property of your text field
    like this
    myTextField_txt.text = "here is the text";
    or if it is inside a movieclip
    myClip_mc.myTextField_txt.text = "here is the text";
    To change the color you would need to put a TextFormat on it. To keep the same fontsize, font etc. you could first get the TextFormat from your existing Textfield, change the color of the TextFormat and set it on the TextField.
    // get the Textformat of the first character
                var TF:TextFormat = myTextField.getTextFormat(0,1)
    // set the font color
                TF.color = 0xff0000;
    // put it on the whole text
                myTextField.setTextFormat(TF)

  • Are there a dynamic way for evaluting variables in as3?

    Hi..!
    eval() is a usefull method or function in javascript.. Because we may define our variables via dynamic way..! There are following code is for understanding that how can define dynamic defining variables in javascript.. And Are there a dynamic way for evaluting variables in as3 like following javascript code?
    <script language="javascript1.2" type="text/javascript">
    var trainOfUfo = "...hi earthling...";
    var handleBlade = eval("train"+"Of" + "Ufo");
    alert(handleBlade);  //-- it appears in dialog box text field area "...hi earthling..."---
    </script>
    Gürkan Şahin
    Code Developer
    Turkey

    In AS3 you can use the bracket notation...
    var trainOfUfo = "...hi earthling...";
    var handleBlade = this["train"+"Of" + "Ufo"];
    AS2 supports the eval() function, but it was done away with in AS3

  • RePost: center movie clips dynamically, as3.0 ?

    I have a question that was somewhat answered but I now have some problems with, as far as implementing the solution is concerned.  I posted in August and I have revisited the file only now to see if I can create the changes necessary to center my mc's dynamically as they are drawn on the stage at runtime.  They need to center to themselves rather than having their registration points in the top left corner, per display object.
    Here is the thread:
    http://forums.adobe.com/message/5760947#5760947
    Thanks in advance for any responses.
    -markerline

    I attempted to reply yesterday but the forums became under maintenance (as we all re-logged in after).
    What I tried to post before the system went down was to give a single example as you had mentioned. To remove the complexity of the rest of the app so this can be understood alone and then implemented into your larger system.
    Centering via container in code is very simple as long as you can grab a hold of the shape in code as well.
    Here's a complete AS3 example of centering a single object inside a container. I just want you to paste this into a new AS3 doc so you can tell me you understand how it works. After that, the more complex multi-object container in a container approach comes in:
    e.g. 2 squares rotating:
    import flash.display.Shape;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.display.Sprite;
    // start rotation loop using a Timer to turn all objects
    var moveTimer:Timer = new Timer(10,0);
    // function to rotate objects
    moveTimer.addEventListener(TimerEvent.TIMER, handleTimer);
    // draw a rect shape
    var redrect:Shape = new Shape();
    redrect.graphics.lineStyle(3,0x0,1,true);
    redrect.graphics.beginFill(0xFF0000);
    redrect.graphics.drawRect(0,0,100,100);
    redrect.graphics.endFill();
    addChild(redrect);
    // position at x:100 / y:100 on stage
    redrect.x = 150;
    redrect.y = 200;
    // now draw a blue square but with a container while centering the shape
    // container
    var blueContainer:Sprite = new Sprite();
    addChild(blueContainer);
    // draw a rect shape
    var bluerect:Shape = new Shape();
    bluerect.graphics.lineStyle(3,0x0,1,true);
    bluerect.graphics.beginFill(0x0000FF);
    bluerect.graphics.drawRect(0,0,100,100);
    bluerect.graphics.endFill();
    blueContainer.addChild(bluerect);
    // position in center of container (subtract half width/height)
    //-------------centering code----------------
    bluerect.x -= bluerect.width / 2;
    bluerect.y -= bluerect.height / 2;
    // position container
    blueContainer.x = 400;
    blueContainer.y = 200;
    // start timer which invokes function below
    moveTimer.start();
    // rotate the red rect (upper left reg) and blue (objects centered);
    function handleTimer(e:TimerEvent):void
              // just rotate both to see the registration
              redrect.rotation += 2;
              blueContainer.rotation += 2;
    Now do understand I know I can draw my bluerect with negative coordinates to achieve the same thing inside the shape (e.g. -50,-50,100,100) but the point here is containing potentially a complex object into a single object so the entire outer contents can be measured and rotated from a single center point. That comes after this simple code is understood.

  • Adding Image to Simple Button Dynamically Using AS3

    Hi,
    I need some help trying to figure out how to dynamically add an image (PNG or JPEG) that I can place in the library to a simple button also dynamically created in AS3.
    Is there a way to (1) add the image instead of using a text label and have it centered in the button?
    Here's the AS3 for the simple button without the image (currently uses text label but would prefer if possible to substitute an image for the text:
            var mc2:MovieClip = new MovieClip();
            mc2.addChild( bgRed2 );
            mc2.addChild( txt2 );//currently uses text label; would prefer to use an image istead of text
            var mc2a:MovieClip = new MovieClip();
            mc2a.addChild( bgRed2a );
            mc2a.addChild( txt2a );currently uses text label; would prefer to use an image istead of text
            var clearBtn:SimpleButton = new SimpleButton();
            clearBtn.upState = mc2;
            clearBtn.overState = mc2a;
            clearBtn.downState = clearBtn.upState;
            clearBtn.hitTestState = clearBtn.upState;
            clearBtn.x = 0;
            clearBtn.y = 0;
            addChild( clearBtn );
            clearBtn.x = 55;
            clearBtn.y = stage.stageHeight-clearBtn.height;
    Any help appreciated.

    assign your image a class name (eg, Img1). you can then use:
    var img1D:BitmapData=new BitmapData();
    var img1:Bitmap=new Bitmap(img1D);
    cleanBtn.upState=img1; // for example, button's upstate is the image.
    // if you wanted some background and the image centered on the background, create your background (sprite or movieclip), use addChild to add img1 to your background and center it.  then assign your button's upState etc to be your background

  • Dynamically creating a AS3.0 code based on animations made at runtime

    Hello everyone,
    I am new to AS3.0 and always getting tasks that is very very challenging. Here is the challenge.
    Need to create a flash application where the user can create animations using images(upload) and text dynamically and export to a swf file. This was my previous post and the answers from the forum members was "impossible - 95%" and "Possible - 5%" (my average calcu).
    http://forums.adobe.com/thread/678202?tstart=0
    Now i got an idea from the "Possible - 5%". That is
    as per the discussion in the above link there are compliers that can create swf files from the command prompt using haxe, swfmill, neko etc etc. these requires a AS3.0 class file to get the output.
    now my question is can we generate the AS3.0 code from the swf file where the animations using images, text are done on the runtime stage. after the user is done with his animations he can click publish btn were we need to create the AS3.0 code and send to the command promt for getting the swf file as output.
    i think this task is quite hard. but any help regarding this will let me in a right direction.
    thanks in adv for any helps

    Assuming that WYSIWYG concept is valid, you are better off with Flex. Flex offers xml structure that you can use as template and just write values. Then this XML can be used by compiler as it is used in Flex.
    In any case, this is a very tedious and advanced task you are embarking on. If you are talking about couple of objects and simple animations - it is not that bad. But if there is more - it is difficult mainly because of the multitude of use cases and exponential growth in objects relationships from both display list and user interaction standpoint.
    I was a part of such project about 2 years ago and I see that one has to be an excellent UX engineer, very good architect and an advanced AS developer in order to make this kind of application worth pursuing.

Maybe you are looking for