AS3 - Accesing dynamic MC

Hello,
From a Thread in this forum, I learned to create dynamic MC
like this:
for (var i:int=0; i<5; i++) {
var mc:MovieClip = new MovieClip();
mc.name = "thumb_"+i;
mc.myNumber = i * i;
this.addChild(mc);
trace(mc.name+", "+mc.myNumber);
results:
thumb_0, 0
thumb_1, 1
thumb_2, 4
thumb_3, 9
thumb_4, 16
but if I want to trace a myNumber from a previous MC, i don't
know how
to do it:
trace(mc.myNumber);
trace(this.thumb_2);
results:
16
undefined
How can I do this? Is thumb_2 deleted by thumb_3, and thumb_3
deleted by
thumb_4?
regards.
Hugo Hiram.

Great!
Thanks!
Hugo Hiram.
kglad escribió:
> :
>
>
>
> i=2;
> var yourSqNum:int =
MovieClip(this.getChildByName("thumb_"+i)).myNumber;

Similar Messages

  • Accesing dynamically generated UI elemnts using Automation tool

    Hi,
    I want to test my iOS app. It contains dynamically generated UI elemnts.
    I can't print them with logElementTree() and I don't know how to access the  dynamically generated elements.
    If there is any way I can access dynamically generated elements using a script?
    Any help will be highly apreciated
    Thank You and best regards
    Aruna

    I am beginning to think that there is no solution to my problem. Let me better define the problem:
    1. Automation tool does not see extended check box.
    2. The container of extended check box is standard tree (nothing to instrument).
    3. Extended check box is third party component which was derived from standard button, and not standard check box (theoretically nothing to instrument again).
    4. Extended check box was used in item renderer class of the tree.
    Maybe elements used in item renderers cannot be exposed to automation tools (I have tried FlexMonkey and RiaTest, but they both failed)?

  • AS3 : Text dynamique et masque

    Bonjour,
    J'essaye d'importer des données provenant d'un xml dans mon flash.
    Ca fonctionne bien lorsque mon texte dynamique n'est pas dans un masque, mais lorsqu'il s'y trouve, ça ne fonctionne plus.
    J'ai bien incorporé les polices comme indiqué dans pas mal de forum, mais rien y fait. Ca fait deux jours que je cherche, mais je ne trouve pas de solution
    Quelqu'un aurait une idée ?
    Voici le mon fichier : Dropbox - v1.rar
    D'avance merci pour votre aide

    Hi Ned,
    Thank you for this suggestion. I substituted <font color='#0000FF'> but got the same result. The text item (link) remains underlined, but no blue color.
    I have been using text format for the text field, which has no special color for a link. Maybe this is over-riding the color choice? (But, doesn't seem to affect the underlining.)
    If I use CSS, I would need to figure out how to change the text format properties into CSS.
    var tfH2:TextFormat = new TextFormat();//current text format applied to this text field
            tfH2.color = 0x000000;
            tfH2.font = "Verdana";
            tfH2.size = 18;
            tfH2.bold = true;
            tfH2.align = "left";
            tfH2.leftMargin = 5;
    //how to write this as myCSS.setStyle and properly tag the text with the <h1> etc.?

  • Getting directory list

    I’ve got an app. that can open and save XML data (using the v10 plug-in). The client wants to add a drop down populated with a list of the XML files saved in a “Sample Calculations” folder. I’m not exactly sure if AS3 can dynamically read the contents of a directory (this would have to work both online and when run as a local app, so server side scripting is not an option). Right now my only idea is to use a manually created XML file that contains a list of the other files in the directory, but this seems quite cumbersome, I’d rather have the app. just dynamically read what’s in the folder. Flash image browsers seem to be able to read all JPG’s in folder X, is this kind of thing done strictly through server side scripting? (or I guess you could also do it using a strict file naming convention and read files sequentially until you get a file not found error, not an option for me).

    Thanks, I was afraid of that. The Air app’s install requirement will make that a non-starter. If this were a high priority feature I’d probably spring for Northcode’s SWF Studio as a local solution, however, using an XML file list gives me at least a 70% solution at no added cost, so that’s probably going to be my approach.

  • 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

  • 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>

  • 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.

  • How to use as3 in flash cs3 to add dynamic text from a text file into a flash file

    let me start out by saying today is my first day of scripting
    in flash.
    I have a text file text.txt
    it contains
    text1=hello world
    can someone please show me how to display this text in a
    flash file
    i have been searching for this for hours and there are
    solutions with flash mx and actionscript 2.0 but i would like to
    see how to do this in as3.
    just a simple frame that loads that file and displays it when
    you test run the program
    much apreciated
    RC

    I'm not up on AS3 yet, but many things are still similar. You
    need to use the LoadVars class to accomplish this, You can find
    information this in Flahs Help>Actionscript>Actionscript
    Language Reference>Actionscript classes.
    rem: the text.txt file and the text.fla file must be in the
    same directory.
    The code will look something like this:

  • Dynamic streaming taking too long time to switch video using NetStreamPlayOptions in AS3

    Hi,
         Can any one tell me why dynamic streaming taking too much time to switch video from lower bit rate to higher bit rate and vice versa.
    I am doing dynamic streaming in following ways -
    var param:NetStreamPlayOptions = new NetStreamPlayOptions();
    param.oldStreamName=oldStream();
    param.streamName=newStream()
    param.transition=NetStreamPlayTransitions.SWITCH;
    ns.play2(param);
    ns.addEventListener(NetStatusEvent.NET_STATUS, switchMode);
    I am using duel buffering and that is 3 seconds when video starts and 10 seconds when "NetStream.Buffer.Full". Video taking approximately 30-50 seconds to switch video and when I am calling the above code.
    Thanks & regards
    Sunil Kumar

    Hi Sunil,
    Was my link useful to you? If you have not gone through the link which I suggested just go through the below lines it may help you:
    For a faster switch with optimal keyframe interval and client-side buffer, when Flash Media Server (FMS) receives a "switch" command, the server waits for a keyframe to switch to the new stream. FMS looks for the keyframes in the new stream in chunks equal to the client's buffer size(NetStream.bufferTime), so having a client buffer larger than the keyframe interval of the stream would help with a fast switch response time from the server—in other words, a shorter delay between a "switch" call to the server and the client receiving bits from the new stream in response.
    Following values are considered most optimal:
    Keyframe interval: 5 sec.
    Client-side buffer: 6–10 sec.
    So to maintain optimal keyframe interval you can go for fresh encoding of your videos which will give you a chance to set keyframe interval or if you dont want to do this then I would suggest you to increase the client-side buffer.
    Regards,
    Amit

Maybe you are looking for