Count number of children movie clips?

I have buttons that create specific movie clips such as a library object named "Clip_1":
function b_Add_Clip_1(event:MouseEvent):void
var b:MovieClip = new Clip_1();
b.name = "Clip_1";
container.addChild(b);
I can add many Clip_1's, Clip_2's and so on, by their corresponding buttons.I cannot figure out how to count the number of them that exist on the stage, however.
I would like the number of Clip_1 instances to display in a text field.
For example: If there are 20 on the stage, the text field should display 20, if one is removed, it should display 19.
I would be grateful for any helpful hints, thank you.

That seems to make sense, too. I will analyze it closely and give it a try, thanks!
SInce then, I've been trying another approach, I'd really appreciate opinions on it.
Setup:
In each clip variety (Clip_1, Clip_2, etc)  there is a common instance called 'control' which performs functions such as drag, rotate and removeChild by referencing its parent.
For example, In control I have code that gets its parent name and displays it in a text field at the root, on hover: Object(root).part_txt.text = Object(this).parent.name;
What I am trying currently:
In control's first frame I place code that grabs the current count in the corresponding count field (based on its parent's name) and adds 1 to it, simply by the instance appearing on the stage.
I am trying to do that by this code:
// Turn the instance name, example: "Clip_1" into a varable "this_part":
var this_part = Object(this).parent.name;
// The count fields are named Clip_1_count, Clip_2_count, etc, taking the value of that field and making it a variabe "c_this_part"
var c_this_part = Number(Object(root[this_part + "_count"].text));
// Now adding 1 to the count field value
var v_this_part:Number = c_this_part+1;
// Then update the count field with the new value
Object(root[this_part + "_count"].text) = String(v_this_part);
If I can get that to work, I can add a similar function to the delete function that subtracts from the count field.
The problem is, Object(root[this_part + "_count"].text) = String(v_this_part); produces this error: 1105: Target of assignment must be a reference value.
Am I missing something obvious? Or is this a fruitless tactic?
Thanks again for your time.

Similar Messages

  • Advice on animating lots of small movie clips

    Hi,
    I have a performance problem that may be best demonstrated
    with an example.
    http://www.b3ta.cr3ation.co.uk/data/swf/game1.swf
    If you look at the animation and watch it for a while you
    will see the
    number of balls growing.
    Initially the performance is so-so but eventually it becomes
    totally
    unacceptable. So I was wondering if anyone could impart
    advice about any
    optimizations.
    Every tile is a movie clip and every ball is a movie clip
    that tweens from
    one tile to the next. I also need to read the frame the clips
    are on but
    when I bound a class to the balls clip it immediatly ran
    unacceptably slow.
    I have a plan B which involves creating tile animations of
    each of the ball
    animations, which I know would create a huge performance gain
    but would mean
    creating 510 tile animations and thus make the animations
    unmaintainable.
    TIA
    Wil

    I created a new tween object just the once for each x and y
    as neeed. Would
    that make much odds?
    Is the other poster kglad correct in saying the number of
    visible movie
    clips in this instance shouldn't be causing problems?
    Cheers
    Wil
    "sly one" <[email protected]> wrote in
    message
    news:enf1hs$rpb$[email protected]..
    > How are you doing the tweens? OnEnterFrames? You will
    want to delete each
    > of
    > the onEnterFrames as they each finish.
    >
    > Other than that you are running into a major Flash wall:
    you can't have
    > hundreds of animations running at the same time. Flash
    just isn't built
    > for
    > that.
    >

  • Using MouseEvent with Movie Clips

    Hopefully i have a real easy question. I have a movie clip
    that i saved in a library. I gave the movie clip an instance name
    so I can instantiate the movie in my document class. The movie clip
    itself has 3 layers.
    So i instantiate the movie clip, add a mouseevent to the
    movie clip instance and then add it to my stage(addchild()). My
    problem is that the MouseEvent.target could be any of the 3 layers
    of my movie clip, I was expecting the MouseEvent.target would be
    the entire movie clip. So when i go to change the x, y position of
    the MouseEvent.target, only the 1 layer moves and my movieclip
    becomes disjoint.
    Hopefully someone can give me an easy way to test to see
    which layer is returned by the MouseEvent and then I can move the
    entire movie clip instead of just the one layer.
    Thanks in advance.

    NedWebs, you hit it on the head. My movie clip is made up of
    movie clips(I dont know what the proper terminology of the
    movieclip that contains the other movie clips, parent movieclip?).
    So is there a way to get back to the parent movieclip when
    one of the children movie clips are targeted? In my action script i
    only instantiate the parent movieclip, so i assume the children
    movie would have to be related to the parent movieclip in some
    fashion.
    So when my MouseEvent.Target is one of those child movieclips
    I need to somehow reference the parent movieclip and move it..
    I dont have the code here with me, but I can post it when i
    get home tonight.
    PS. I guess i should have created this topic in the AS 3.0
    forum.

  • Looping a movie clip a specific number of times in Flash

    Does anyone know how to get a movie clip to loop a specific number of times in Flash? I know how to stop a movie clip from looping by using the this.stop (); command by placing the command in a separate Action Script layer, in a keyframe, inside of the movie clip's timeline. This allows the movie clip to play through once and then stop. But I need for the movie clip to loop more than once, maybe 2 or 3 times, and then go back to the main timeline. Does anyone know the code for this?
    Also, is it possible to place a pause (I'm guessing, maybe by using a timer of some type?) between the loops, so that the movie will pause a couple of seconds before it loops again and then stop? Please note I do not need the movie clip to stop when there's an event like a rollover or anything. I just need it to play a couple of times, pause between plays and then stop and go back to the main timeline. Please let me know if anyone can help.
    Thanks,
    Sarah
    P.S. Is there a good, easy to use, reference book anyone can recommend for creating specific things in Flash using Action Script? Do you guys have a favorite for beginners like me?

    You can use a variable to keep count of how many times you loop, and until it exceeds a particulr value (2 or 3) you execute a setTimeout() call that waits for however long you want to delay and then tells the movieclip to gotoAndPlay(1).
    So in the first frame you would establish the counting variable...
    var count;
    if(count == undefined){ // only set it to 0 once
    count = 0;
    and in the last frame you would do your incrementing and control....
    stop();
    count += 1;
    if(count < 3){
    setTimeout(waitABit, 2000); // call function in 2 secs
    function waitABit(){
    gotoAndPlay(1);

  • Urgent : Flash CC File is corrupted, symbol (movie clip) are empty, use count : 0 . ONE week of work lost, need help!

    Hello,
    I have been working on a Flash File with a lot of animations / symbols etc, and on thursday (during the Adobe Update), when I opened my file, all the symbol (movie clip) are empty, use count : 0.
    The size of the file is still the same though, 35mo.
    I had only this file, I really need help to repair it...
    Please let me know if you have a solution.
    Thank you!

    hi,
    Can you please share the file which got corrupted?
    Was the original file created in older version(CS6 and below) of Flash?
    Were you trying to open the file in Flash CS6?
    Did your original file had symbol names containing | : ; & * , etc.characters or leading/trailing spaces?
    Rgds,
    Mukesh

  • Removing movie clips with added children

    If I have a movie clip added as a child to another movie clip
    on the stage, and I remove it's parent, and null all references to
    the parent, will both the parent and child movie clip be deleted by
    the garbage collector? If so, will it be done on it's regular pass
    or by mark and sweep?

    OK, so if I add a movie clip like this:
    function addMovie()
    var toAdd:MovieClip = new Example(); // example extends
    movieclip
    this.addChild(toAdd);
    I'm assuming that toAdd will be nulled when the function is
    complete, because it's a local variable. Then if I put code inside
    the movie clip at a certain frame or in a function in the class
    Example to get rid of it:
    this.parent.removeChild(this);
    I'm assuming that's all i need to do to get rid of it. I
    can't null the instance of the class Example using this = null from
    inside it, and the only reference to it is the child reference from
    the parent.
    Am I right or is there more I need to do to make the instance
    of example eligible for GC?

  • How to stop a slideshow and show another movie clip at the end?

    Currently my slideshow is in a loop. At the end of last slideshow, I want to show another movie clip (End_mv) that's on another layer. How do I do that? My current scripts are below:
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    //change scale on an image
    var fadeTween:Tween;
    //To slide in on X axis
    var slideXTween:Tween;
    //To slide in on Y axis
    var slideYTween:Tween;
    //To fade IN
    var alphaTween:Tween;
    //To get bigger on its X axis
    var scaleXTween:Tween;
    //To get bigger on its Y axis
    var scaleYTween:Tween;
    //var fadeTween:Tween;
    //description place holder
    var strDescrp:String;
    //source place holder
    var strSource:String;
    //x poistion
    var posX:Number;
    //y position
    var posY:Number;
    //degree rotation
    var degreeRot:Number;
    // delay between slides
    //const TIMER_DELAY:int = 5000;
    var TIMER_DELAY:int = 5000;
    // fade time between slides
    const FADE_TIME:int = 3;
    // reference to the current slider container
    var currentContainer:Sprite;
    // index of the current slide
    var intCurrentSlide:int = -1;
    // total slides
    var intSlideCount:int;
    // timer for switching slides
    var slideTimer:Timer;
    // slides holder
    var sprContainer1:Sprite;
    var sprContainer2:Sprite;
    // slides loader
    var slideLoader:Loader;
    // url to slideshow xml
    var strXMLPath:String = "lstHouse.xml";
    // slideshow xml loader
    var xmlLoader:URLLoader;
    // slideshow xml
    var xmlSlideshow:XML;
    var txtField:TextField = new TextField();
    var formatText:TextFormat = new TextFormat();
    //start of sound section is for sound
    var soundReq:URLRequest = new URLRequest("PaukenBrumfiel_AngelsOnHigh.mp3");
    var sound:Sound = new Sound();
    sound.load(soundReq);
    sound.addEventListener(Event.COMPLETE, onComplete);
    //end of sound section
    function onComplete(event:Event):void
        sound.play();
    function init():void
        // create new urlloader for xml file
        xmlLoader = new URLLoader();
        // add listener for complete event
        xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
        // load xml file
        xmlLoader.load(new URLRequest(strXMLPath));
        // create new timer with delay from constant
        slideTimer = new Timer(TIMER_DELAY);
        // add event listener for timer event
        slideTimer.addEventListener(TimerEvent.TIMER, switchSlide);
        // create 2 container sprite which will hold the slides and
        // add them to the masked movieclip
        sprContainer1 = new Sprite();
        sprContainer2 = new Sprite();   
        mcSlideHolder.addChild(sprContainer1);
        mcSlideHolder.addChild(sprContainer2);
        // keep a reference of the container which is currently
        // in the front
        currentContainer = sprContainer2;
    function onXMLLoadComplete(event:Event):void
        // create new xml with the received data
        xmlSlideshow = new XML(event.target.data);
        // get total slide count
        intSlideCount = xmlSlideshow..image.length();
        // switch the first slide without a delay
        switchSlide(null);
    function fadeSlideIn(e:Event):void {
        // add loaded slide from slide loader to the
        // current container
        currentContainer.addChild(slideLoader.content);
        // clear preloader text
        //mcInfo.lbl_loading.text = "";
        // fade the current container in and start the slide timer
        // when the tween is finished
        //Tweener.addTween(currentContainer, {alpha:1, time:FADE_TIME, onComplete:function() { slideTimer.start(); }});       
        //strSource = xmlSlideshow.image[intCurrentSlide].@src;
        fadeTween = new Tween(currentContainer, "alpha", Regular.easeInOut, 0, 1, 2, true)
        //scale = new Tween(currentContainer, "alpha", Regular.easeInOut, 0, 1, 2, true)
        slideTimer.start()
        onComplete:function();
    function switchSlide(e:Event):void
        // check, if the timer is running (needed for the
        // very first switch of the slide)
        if(slideTimer.running)
            slideTimer.stop();
        // check if we have any slides left and increment
        // current slide index
        if(intCurrentSlide + 1 < intSlideCount)
            intCurrentSlide++;
        // if not, start slideshow from beginning
        else
            intCurrentSlide = 0;
        // check which container is currently in the front and
        // assign currentContainer to the one that's in the back with
        // the old slide
        if(currentContainer == sprContainer2)
            currentContainer = sprContainer1;
        else
            currentContainer = sprContainer2;
        // hide the old slide
        currentContainer.alpha = 0;
        // bring the old slide to the front
        mcSlideHolder.swapChildren(sprContainer2, sprContainer1);
        strDescrp = xmlSlideshow.image[intCurrentSlide].@desc;
        //strSource = xmlSlideshow.image[intCurrentSlide].@src;
        //txtField.border = true;
        //txtField.x = 0;
        //txtField.y = 600;
        txtField.width = 855;
        txtField.height = 200;   
        //txtField.background = true;
        //txtField.backgroundColor = 0xEE9A00;
        txtField.alpha = 20;
        txtField.text = strDescrp;
        formatText.align = TextFormatAlign.CENTER;
        //txtField.autoSize = TextFieldAutoSize.LEFT;
        formatText.color = 0x000;
        formatText.size = 30;
        txtField.x = 0;
        txtField.y = 550;
        posX = 0;
        posY = 0;
        degreeRot = 0;
        // create a new loader for the slide
        slideLoader = new Loader();
        // add event listener when slide is loaded
        slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeSlideIn);
        // load the next slide
        slideLoader.load(new URLRequest(xmlSlideshow.image[intCurrentSlide].@src));   
        addChild(txtField);
        txtField.setTextFormat(formatText)
    // init slideshow
    init();

    I got this error:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
        at flash.display::DisplayObjectContainer/swapChildren()
        at University_Advancement_Holiday_Greeting2012_fla::MainTimeline/switchSlide()
        at flash.utils::Timer/_timerDispatch()
        at flash.utils::Timer/tick()
    And here's the code:
    // import tweener
    //import caurina.transitions.Tweener;
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    import flash.display.MovieClip;
    //change scale on an image
    var fadeTween:Tween;
    //To slide in on X axis
    var slideXTween:Tween;
    //To slide in on Y axis
    var slideYTween:Tween;
    //To fade IN
    var alphaTween:Tween;
    //To get bigger on its X axis
    var scaleXTween:Tween;
    //To get bigger on its Y axis
    var scaleYTween:Tween;
    //var fadeTween:Tween;
    //description place holder
    var strDescrp:String;
    //source place holder
    var strSource:String;
    //x poistion
    var posX:Number;
    //y position
    var posY:Number;
    //degree rotation
    var degreeRot:Number;
    // delay between slides
    //const TIMER_DELAY:int = 5000;
    var TIMER_DELAY:int = 5000;
    // fade time between slides
    const FADE_TIME:int = 3;
    // reference to the current slider container
    var currentContainer:Sprite;
    // index of the current slide
    var intCurrentSlide:int = -1;
    // total slides
    var intSlideCount:int;
    // timer for switching slides
    var slideTimer:Timer;
    // slides holder
    var sprContainer1:Sprite;
    var sprContainer2:Sprite;
    // slides loader
    var slideLoader:Loader;
    // url to slideshow xml
    var strXMLPath:String = "lstHouse.xml";
    // slideshow xml loader
    var xmlLoader:URLLoader;
    // slideshow xml
    var xmlSlideshow:XML;
    var txtField:TextField = new TextField();
    var formatText:TextFormat = new TextFormat();
    //var myEnding:MovieClip = stage.getChildByName('End_mc') as MovieClip;
    //start of sound section is for sound
    var soundReq:URLRequest = new URLRequest("PaukenBrumfiel_AngelsOnHigh.mp3");
    var sound:Sound = new Sound();
    sound.load(soundReq);
    sound.addEventListener(Event.COMPLETE, onComplete);
    //end of sound section
    function onComplete(event:Event):void
        sound.play();
    function init():void
        //reference my movie clip "End_mc" oon the stage and turn its visibility off
        MovieClip(getChildByName('End_mc')).visible = false;
        // create new urlloader for xml file
        xmlLoader = new URLLoader();
        // add listener for complete event
        xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);
        // load xml file
        xmlLoader.load(new URLRequest(strXMLPath));
        // create new timer with delay from constant
        slideTimer = new Timer(TIMER_DELAY);
        // add event listener for timer event
        slideTimer.addEventListener(TimerEvent.TIMER, switchSlide);
        // create 2 container sprite which will hold the slides and
        // add them to the masked movieclip
        sprContainer1 = new Sprite();
        sprContainer2 = new Sprite();   
        mcSlideHolder.addChild(sprContainer1);
        mcSlideHolder.addChild(sprContainer2);
        // keep a reference of the container which is currently
        // in the front
        currentContainer = sprContainer2;
    //function onXMLLoadComplete(e:Event):void
    function onXMLLoadComplete(event:Event):void
        // create new xml with the received data
        xmlSlideshow = new XML(event.target.data);
        // get total slide count
        intSlideCount = xmlSlideshow..image.length();
        // switch the first slide without a delay
        switchSlide(null);
    function fadeSlideIn(e:Event):void {
        // add loaded slide from slide loader to the
        // current container
        currentContainer.addChild(slideLoader.content);
        // clear preloader text
        //mcInfo.lbl_loading.text = "";
        // fade the current container in and start the slide timer
        // when the tween is finished
        //Tweener.addTween(currentContainer, {alpha:1, time:FADE_TIME, onComplete:function() { slideTimer.start(); }});       
        //strSource = xmlSlideshow.image[intCurrentSlide].@src;
        fadeTween = new Tween(currentContainer, "alpha", Regular.easeInOut, 0, 1, 2, true)
        //scale = new Tween(currentContainer, "alpha", Regular.easeInOut, 0, 1, 2, true)
        slideTimer.start()
        onComplete:function();
    function switchSlide(e:Event):void
        // check, if the timer is running (needed for the
        // very first switch of the slide)
        if(slideTimer.running)
            slideTimer.stop();
        // ADDED: Check if using sprContainer2 and at the last slide
        //if ((currentContainer == sprContainer2) && (intCurrentSlide == intSlideCount))
        trace("Current Slide: " + intCurrentSlide);
        trace("SlideCount: " + intSlideCount);
        if ((currentContainer == sprContainer2) && ((intCurrentSlide + 1) == intSlideCount))
            // hide the slideshow (and other related elements, or remove them if desired)
            //mcSlideHolder.visible = false;
            // remove any clips directly inside slideshow (any timers/etc need to be stopped too)
             while (mcSlideHolder.numChildren > 0)
                mcSlideHolder.removeChildAt(0);
            // I do see a var named 'sound' playing so you might want to:
             //sound.stop();
             //sound = null;
            // etc any other slideshow-only elements to hide/remove..
            // play your movie
            MovieClip(getChildByName('End_mc')).visible = true;
            MovieClip(getChildByName('End_mc')).play();       
        // check if we have any slides left and increment
        // current slide index
        if(intCurrentSlide + 1 < intSlideCount)
            intCurrentSlide++;
        // if not, start slideshow from beginning
        else
            intCurrentSlide = 0;
        // check which container is currently in the front and
        // assign currentContainer to the one that's in the back with
        // the old slide
        if(currentContainer == sprContainer2)
            currentContainer = sprContainer1;
        else
            currentContainer = sprContainer2;
        // hide the old slide
        currentContainer.alpha = 0;
        // bring the old slide to the front
        mcSlideHolder.swapChildren(sprContainer2, sprContainer1);
        strDescrp = xmlSlideshow.image[intCurrentSlide].@desc;
        //strSource = xmlSlideshow.image[intCurrentSlide].@src;
        //txtField.border = true;
        //txtField.x = 0;
        //txtField.y = 600;
        txtField.width = 855;
        txtField.height = 200;   
        //txtField.background = true;
        //txtField.backgroundColor = 0xEE9A00;
        txtField.alpha = 20;
        txtField.text = strDescrp;
        formatText.align = TextFormatAlign.CENTER;
        //txtField.autoSize = TextFieldAutoSize.LEFT;
        formatText.color = 0x000;
        formatText.size = 30;
        txtField.x = 0;
        txtField.y = 550;
        posX = 0;
        posY = 0;
        degreeRot = 0;
        // create a new loader for the slide
        slideLoader = new Loader();
        // add event listener when slide is loaded
        slideLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeSlideIn);
        // add event listener for the progress
        //slideLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);
        // load the next slide
        slideLoader.load(new URLRequest(xmlSlideshow.image[intCurrentSlide].@src));   
        addChild(txtField);
        txtField.setTextFormat(formatText)   
    // init slideshow
    init();

  • Dynamically adding multiple instances of a movie clip to the stage with one button

    hello,
    I was wondering if there was a way to add several instances
    of the same movie clip to the stage dynamically utilizing one
    button.
    I can do one with the following code placed on the button...
    on (release) {
    attachMovie ("filledCircle", "filled1", 5);
    filled1._x = 370;
    filled1._y = 225;
    But I want the user to be able to hit the button again and
    get yet another instance of "filledCircle" on the stage.
    I also want the user to be able to drag these instances
    around...
    Any help would be appreciated...
    Thanks,
    Muhl

    Muhl,
    > I was wondering if there was a way to add several
    > instances of the same movie clip to the stage
    > dynamically utilizing one button.
    Sure thing.
    > I can do one with the following code placed on the
    > button...
    >
    > on (release) {
    > attachMovie ("filledCircle", "filled1", 5);
    > filled1._x = 370;
    > filled1._y = 225;
    > }
    Gotcha.
    > But I want the user to be able to hit the button again
    > and get yet another instance of "filledCircle" on the
    > stage.
    You're in luck, because this isn't very hard to do. The main
    thing to
    keep in mind is that each instance must have A) its own
    unique instance name
    and B) its own unique depth. In your example, the instance
    name is filled1
    and the depth is 5. The next clip's instance name should be
    filled2 at a
    depth of 6. Then filled3, depth 7, and so on. You can use a
    single
    variable to handle the incrementation.
    // code in a frame
    var counter:Number = 1;
    // code on your button
    on (release) {
    attachMovie ("filledCircle", "filled" + counter, counter +
    4);
    With me so far? The variable counter contains the numeric
    value 1. The
    second parameter of attachMovie() is provided with a
    concatenation of
    "filled" + 1, which makes "filled1". The third parameter is
    provided with
    the sum of counter plus 4, which makes 5. Obviously, we need
    a bit more.
    The button must, in addition, increment the value of counter.
    The ++
    operator handles this perfectly.
    on (release) {
    attachMovie ("filledCircle", "filled" + counter, counter +
    4);
    counter++;
    Now, it seems you also want to position the attached movie
    clip to (370,
    225). Are they call supposed to go to the same place? If so,
    you may use a
    second variable to hold a reference to the newly attached
    clip. Look up
    MovieClip.attachMovie(), and you'll see that the method
    returns the exact
    reference you need.
    // code in a frame
    var counter:Number = 1;
    var mc:MovieClip;
    // code on your button
    on (release) {
    mc = attachMovie ("filledCircle", "filled" + counter,
    counter + 4);
    counter++;
    mc._x = 370;
    mc._y = 225;
    Make sense?
    > I also want the user to be able to drag these instances
    > around...
    Then you need to handle a few events. You're dealing with
    movie clips
    here, so your best bet is to study up on the MovieClip class,
    which defines
    all movie clips. (Note, also, that the TextField class
    defines all input
    and dynamic text fields; the Sound class defines all sounds,
    etc. This is a
    very handy arrangement of the ActionScript 2.0 Language
    Reference.)
    // code in a frame
    var counter:Number = 1;
    var mc:MovieClip;
    // code on your button
    on (release) {
    mc = attachMovie ("filledCircle", "filled" + counter,
    counter + 4);
    counter++;
    mc._x = 370;
    mc._y = 225;
    mc.onPress = function() {
    this.startDrag();
    mc.onRelease = function() {
    this.stopDrag();
    Easy as that. You're simply assigning a function literal to
    the event
    of each new MovieClip instance as you create it. Take a look
    and you'll see
    each of these class members available to you -- that is, to
    all movie clips.
    MovieClip.onPress, MovieClip.startDrag(), MovieClip._x, etc.
    Wherever it shows the term MovieClip in the Language
    Reference, just
    replace that with the instance name of your clip -- or a
    reference to that
    clip (which even includes the global "this" property).
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • HitTesting edges / moving Movie Clips stage length

    This is sort of a multi-layered question- I have a movie clip that I sectioned off in quadrants:
    http://img401.imageshack.us/img401/2250/tempnw.jpg
    The red dot is the player, the stage is the size of one square. My goal is to, when the player moves to either of the 4 edges, the next section of the quadrant comes up (meaning if the player moves to the right edge, the section that borders the right edge will slide on screen, and the old section will slide off screen).
    I was wondering if there was a way to hitTest if an object is touching any part of the edges? Is the hitTestPoint method something I should look into? What I have so far is an object off screen (black rectangle), that when the player touches the quadrants slide like I want them to (at least I'm trying to make that work).
    Here is my code. I know some of it's wrong and/or I'm missing something. Any help would be appreciated.
    if(leftKeyIsDown && player_mc.x > -15)     //-15 is half the size of the temporary player_mc
              player_mc.x -= speed;
              if(player_mc.x < 0)     //take in account the size of the REAL player_mc
                   player_mc.gotoAndPlay(1);
                   stage.removeEventListener(KeyboardEvent.KEY_DOWN, pressKey);
                   stage.removeEventListener(KeyboardEvent.KEY_UP, releaseKey);
                   if(player_mc.hitTestObject(edge_mc))
                        map_mc.x = map_mc.x + stage.stageWidth;
              //map_mc.addEventListener(MotionEvent.MOTION_START, moveMap);
              //checkHitLocation(edge);
    /*function checkHitLocation():void
    /*function moveMap(event:MotionEvent):void
         var pointLeft:Point = new Point (0, 150.45);
         if(player_mc.hitTestPoint(pointLeft.x, pointLeft.y, true))
              map_mc.x -= stage.stageWidth;
    Also, I have it so all the quadrants together will be in a movie clip (map_mc), and nested in that movie clip will be the individual pieces, each quadrant with an individual instance name.

    I think my inability to understand array's and how to add/remove children from them is leading me to hit a wall. Would you mind helping explain it to me?
    package
         import flash.display.MovieClip;
         import flash.events.KeyboardEvent;
         import flash.events.Event;
         import flash.ui.Keyboard;
         public class Main extends MovieClip
              public var ground:MovieClip;
              public var nextGround:MovieClip;
              public var player:MovieClip;
              public var keyPressed:uint;
              public var rightKeyIsDown:Boolean;
              public var leftKeyIsDown:Boolean;
              public var speed:Number = 10;
              public var land:Array = new Array();
              public var landOrigin:Number = 650;
              public function Main()
                   ground = new beginGround_mc();
                   addChild(ground);
                   player = new player_mc();
                   addChild(player);
                   player.y = 200;
                   rightKeyIsDown = false;
                   leftKeyIsDown = false;
                   stage.addEventListener(KeyboardEvent.KEY_DOWN, pressKey);
                   stage.addEventListener(KeyboardEvent.KEY_UP, releaseKey);
                   stage.addEventListener(Event.ENTER_FRAME, hitting);
              public function hitting(event:Event):void
                   if(player.hitTestObject(ground.groundAdd1_mc))
                        trace("hit");
                        addNewGround();
                   for(var i:uint = 0; i < land.length; i++)                    //1
                        nextGround = land[i];
                        if(player.hitTestObject(nextGround.groundAdd2_mc))
                             trace("blue");
              public function addNewGround()                                       //2
                   nextGround = new ground_mc();
                   addChildAt(nextGround, 0);
                   nextGround.x += 700;
                   land.push(nextGround);
    As my code stands right now I got groundAdd2_mc to trace back the second statement. From here I need to keep adding instances of the nextGround movieclip right after one another every time the player hits groundAdd2_mc, and removing all the old ones the player can no longer see.
    I guess I really don't comprehend what //1 is doing, In my mind I put an instance of the nextGround_mc class in the land array and try and call it every time the player hits the appropriate hitTest, leading me to //2 addNewGround, where the new ground piece is added 'x' distance away; I'm not really comprehending how I can add only 1 instance 'x' distance away every time the player hits the hitTest.

  • Load all movie clips

    Hi,
    I have a "map_mc" movie clip that has over 500 movie clips(counties). I also have the countynames in xml format.  I want to be able to
    1.  in a loop get a list of all movie clips
    2. and in a dynamic text box assign the county name to the movie clip (from xml).
    Is it possible to get the names of all movie clips and then assign the countynames?
    I have the xml part semi working and on mouseover can display the name but is stuck on the movie clip part.
    I am trying to avoid typing all the county names  and in the future will be adding census and other data to the xml.
    can someone help?

    if you had an xmlList of 500 countynames, and if the 500 movieclips inside maps_mc each had names such as mc0, mc1, mc2, etc, you could loop thru them like this:
    for(var i = 0; i < xmlList.length(); i++){
         //get reference to county movieclip
         var mc = maps_mc.getChildByName("mc" + i);
         //then add listeners
         mc.addEventListener(MouseEvent.ROLL_OVER, overMe);
         mc.addEventListener(MouseEvent.ROLL_OUT, outMe);
    function overMe(e:MouseEvent){
         //the county you rolled over
         var mc = e.target;
         //extract the number from the name
         var n = Number(mc.name.substr(2));
         //use n to get countyname from xmlList
         var countyname = xmlList[n];
         trace(countyname);
         //now add countyname to a textField
         textField.text = countryname;
    function outMe(e:MouseEvent){
         //clear textField
         textField.text = "";

  • Looping movie clips

    I want to loop 5 movie clips so that one clip moves onto the stage, stays there for a certain time, then moves off the stage, then the next one.
    Any help is greatly appreciated!
    Here's what I've got so far:
    var m1_mc = new m1();
    var m2_mc = new m2();
    var m3_mc = new m3();
    var m4_mc = new m4();
    var m5_mc = new m5();
    currentPage = m1_mc;
    var timer:Timer = new Timer(1000);
    timer.addEventListener(TimerEvent.TIMER, onTimer);
    timer.start();
    function onTimer(evt:TimerEvent):void {
    for (var i:Number = 0; i<5; i++){
    prevPage = currentPage;
    var exitTween:Tween = new GCSafeTween(currentPage,"x",Strong.easeOut,currentPage.x,-800,12,false);
    //this is where I am getting stuck. Not sure how to write currentPage + 1 to make the next movie clip play
    exitTween.addEventListener(TweenEvent.MOTION_FINISH, animateOn);
    function animateOn(e:TweenEvent):void{
    var enterTween:Tween = new GCSafeTween(currentPage,"x",Strong.easeOut,-800,0,12,false);

    You should probably step back and rethink things a bit, though not entirely, possibly take it one step at a time.  Get one piece to play properly, then work in having 5 of them.  Using the tween event listeneres amd the timer to trigger things is a good approach.
    Tween-In -> Timer -> Tween-Out -> next Tween-In...
    That for loop inside the function will execute immediately, creating 5 tweens for the currentPage, etc... which is not what I think you want.
    Use a counter variable to keep track of which mc you are dealing with and use it/increment it to define which mc you are dealing with...
    var mcNum:uint = 1;
    var currentPage:MovieClip = this["m"+mcNum+"_mc"];
    and don't forget that you need to add the instances to the movie before you can expect them to be present/visible in any way (addChild())

  • Dynamically call movie clips

    I am creating an animation that has a rotating globe that
    then fades out and that is attached dynamically. I created 3 movie
    clips that I need to bring in while the globe animation is going
    and before it fades out. I need the movie clips to come in AFTER
    the globe has started spinning, and then one at a time play. Then
    once the last logo has come in, the globe should fade out. I need
    to do this all dynamically in AS. I have the globe animation but it
    fades out automatically not when the logos are done, and I figured
    out how to bring in the movie clips but not at the right time. I'm
    very new to Flash and AS and I just can't figure out how to do it.
    Can anyone point me in the right direction?
    The script for the globe is as follows:

    If there is a loop function somewhere for the motion, then
    you could probably delay the logos loading by setting a counter
    that triggers their loading when it reaches x number of rotations,
    say counter = 1, load first logo, counter = 2, load second logo,
    etc... counter = 4, fade the earth.
    By the code you show above, the logos would be appearing
    instantly, so what you could do is have them added thru a function
    instead. That function gets called based on the counter value in
    the earth looping code.
    If the file is reasonably small, I'd be willing to give it a
    looking over to see if I can offer some suggestions specific to
    what you already have.

  • Problem with accessing dynamically created movie clips, returns null...

    Hopefully this is a stupid question with an easy answer, if my code is straight forward enough.
    I am using this snippet of code to create menu items, and then use the jCount variable below to give the clips an index number, like so (which seems to be working just fine):
    for(var j:Number=0;j<xmlSubMenuLength;j++){ 
        var mcSubMenuItem:mcSubMenu=new mcSubMenu();   
        addChild(mcSubMenuItem);    
        jCount++;   
        mcSubMenuItem.name = "mcSubMenuItem" + jCount;
        //traces out names correctly
        trace ("---------------------------------jCount NAME = "+ mcSubMenuItem.name);
        mcSubMenuItem.x=mcMenuHolder.x+20;
        mcSubMenuItem.y =mcMenuHolder.y;
        mcSubMenuItem.y+= nextBtnY;
        nextBtnY+=subtopicSpace;
        global_subi.text = String(jCount); //i see the proper count of 10 in the text field
    However, when I try to access the clips using this snippet:  
    for(var j:Number=0;j<Number(global_subi.text);j++)//
      trace("GLOBAL SUBI = "+ String(global_subi.text));  //traces out 10, which it should
      var scSubMenuItem:String = "mcSubMenuItem" + j;  
      var scSubContent:Object = this.getChildByName(scSubMenuItem);
      trace(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>scSubContent:Object = "+ scSubContent); //returns null!
    My last trace statement returns null. Can anyone see my error, or explain why I can't access my clips after they have been created?
    Thank you muchly,
    ~Chipleh

    Hi kglad,
    Thanks for the response.
    "it's not clear from the shown code that jCount is initialized." - I've posted the relevant code below, which shows that I'm initializing jCount.
    "and it's not clear why you don't use j instead of jCount in that for-loop" - j is used as loop for creating the subtopic movie clips within the i for-loop. So, for each topic in i for-loop, create a group of suptopics using the j for-loop. The j for-loop re-initiates j every time the length of the subtopics is reached(if that makes any sense) - i.e. topic1>subtopic 1,2,3,4 : topic2>subtopic>1,2 : topic3>subtopic1,2,3,4
    jCount is used to keep a running count of the total number of subtopcs created - i.e. per the example above, jCount will display 10.
    var topicSpace:uint=button_mc.height;
    var subtopicSpace:uint = button_mc.height;
    var nextBtnY:uint = 0;//whatever;
    var jCount:Number = 0;
    function createXMLMenu(menuLength:Number,itemName:XMLList):void{
         var navItemText:XMLList = itemName;
          for(var i:Number=0;i<menuLength;i++)
               var mcMenuItem:mcMenu=new mcMenu();        
               addChild(mcMenuItem); 
               mcMenuItem.btnTxt.htmlText = i+1 +". " +navItemText[i];  
               mcMenuItem.ivar = i;  
               mcMenuItem.name = "mcMenuItem" + i;  
               mcMenuItem.x=mcMenuHolder.x;
               mcMenuItem.y =mcMenuHolder.y;
              //kglad's addition
               mcMenuItem.y+= nextBtnY;
               nextBtnY+=topicSpace; 
               var subVar:Number = i;//mcMenuItem.ivar 
               //Submenu content
               var xmlSubMenuLength:Number = xml.sim.bodyText.page[i].subpage.length()
               var menuItemAttachment:MovieClip = MovieClip(mcMenuItem); 
               for(var j:Number=0;j<xmlSubMenuLength;j++)
                     var xmlSubPageNumber:XMLList = xml.sim.bodyText.page[subVar].subpage;
                     var subNavLinkNumber:Number = xmlSubPageNumber[j];
                     var subTitleText:String = xml.sim.bodyText.page[subVar].subpage.subNavItem[j];
                     var mcSubMenuItem:mcSubMenu=new mcSubMenu();
                     trace("mcSubMenuItem.ivar = "+ j+1);
                     var mc2Attach2:MovieClip = MovieClip(menuItemAttachment);
                     mcSubMenuItem.btnTxt.htmlText = j+1 +". " +subTitleText;   
                     mcSubMenuItem.ivar = Number(subVar);
                     mcSubMenuItem.jvar = Number(j);
                     addChild(mcSubMenuItem);
                     jCount++;   
                     mcSubMenuItem.name = "mcSubMenuItem" + jCount;
                     trace ("---------------------------------jCount NAME = "+ mcSubMenuItem.name);
                     mcSubMenuItem.x=mcMenuHolder.x+20;
                     mcSubMenuItem.y =mcMenuHolder.y;
                     //kglad's addition
                     mcSubMenuItem.y+= nextBtnY;
                     nextBtnY+=subtopicSpace;    
                     global_subi.text = String(jCount);
                mcSubMenuItem.lExtend.visible = false;  
    global_i.text = String(i);
    Then I try to access the clips like so:
    -The first for-loop access the topic movie clips, no problem, and traces out scContent correctly.
    -The second for-loop traces out null everytime, when I would expect it to be tracing out the names of the subtopic movie clips.
    function accessClips(){
         //This will access the topic movie clips
         for(var i:Number=0;i<Number(global_i.text);i++)
               var scMenuItem:String = "mcMenuItem" + i;
               var scContent:Object = this.getChildByName(scMenuItem);            
               trace(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>scContent:Object = "+ scContent);
         //This is supposed to access the subtopic movie clips
         for(var j:Number=0;j<Number(global_subi.text);j++)//
               var scSubMenuItem:String = "mcSubMenuItem" + j;
               var scSubContent:Object = this.getChildByName(scSubMenuItem);
               trace(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>scSubContent:Object = "+ scSubContent);
    Hope this makes sense, Chipleh confused. If the code is not clear enough, let me know and I'll try to further clarify.
    Thanks again,
    ~Chipleh

  • Stop movie clip

    I found some code on the web for confetti. The actual Movie
    clip is just one small dot. in the Scene you place action script to
    create the confetti effect. But you don't move the movie clip (dot)
    itself into the Scene.
    I can't figure out how to stop it at a certain point when I
    no longer want it. I've tried various combinations of stop();
    gotoAndStop(target or frame #). I've tried putting it in the
    actionscript that creates the confetti effect, in the moviie clip
    timeline and alone in the main tiimeline.
    nothing is working.
    any help would be appreciated. thank you.

    Thank you but that didn't work either. Below is the code. On
    the sample I found, it included only this code in the Timeline on a
    layer called actions, and the moveclip in the library; the movie
    clip is not in the timeline. and it works. it just doesn't stop.
    screen_width=800
    screen_height=200
    frecuency=0//<< INCREASE NUMBER TO REDUCE PAPERS
    QUANTITY
    MovieClip.prototype.serConfeti=function () {
    this._x=Math.ceil(Math.random()*screen_width)
    this._xscale=Math.ceil(Math.random()*screen_height)
    this._yscale=this._xscale
    this.mover()
    this.coloreame()
    function getPorcentaje() {
    var numero=Math.ceil(Math.random()*100)
    return numero
    function getOffset() {
    var numero=Math.ceil(Math.random()*255)
    var buleano=Math.round(Math.random()*1)
    if (buleano==1) {
    numero=numero*1
    return numero
    MovieClip.prototype.coloreame=function () {
    var my_color=new Color(this)
    var nuevo_color= new Object()
    nuevo_color.ra=getPorcentaje()
    nuevo_color.rb=getOffset()
    nuevo_color.ga=getPorcentaje()
    nuevo_color.gb=getOffset()
    nuevo_color.ba=getPorcentaje()
    nuevo_color.bb=getOffset()
    my_color.setTransform(nuevo_color)
    MovieClip.prototype.mover=function () {
    this.onEnterFrame=function () {
    if (this._y<600) {
    this._y+=10
    this._xscale=Math.random()*200
    this._rotation=Math.random()*360
    } else {
    this.removeMovieClip()
    MovieClip.prototype.caidaConfeti=function () {
    this.createEmptyMovieClip("caida_mc",1)
    var count=0
    var confCount=1
    this.caida_mc.onEnterFrame=function () {
    if(count<frecuency){
    count++
    } else {
    this.attachMovie("conf","conf"+confCount,confCount)
    eval("this.caida_mc.conf"+confCount).serConfeti()
    count=1
    confCount++
    _root.caidaConfeti();
    // in this case this represents _root.
    // so, if You want to use the caidaConfeti() prototype into a
    MovieClip
    // yo can do this for example:
    MyMovieClip.caidaConfeti()

  • Targeting movie clips

    Hello everyone,
    I've worked on some code with a little help from some people
    here and I've gotten everything to work. The problem I am having
    right now is getting my cross fading images to sit inside separate
    movie clips that are on my home .swf. The code I have so far is as
    follows:
    var showTime:Number = 5000 // milliseconds the picture shows
    at 100% alpha.
    mc_Mon1 = createEmptyMovieClip("img1_mc", 0);
    loadMovie("images/home/image01.jpg", img1_mc); // load
    picture from the file directory that your .swf is in.
    mc_Mon1 = createEmptyMovieClip("img2_mc",
    getNextHighestDepth());
    loadMovie("images/home/image02.jpg", img2_mc);// load picture
    from the file directory that your .swf is in.
    img2_mc._alpha = 0; // hide 2nd picture
    var duration:Number = 30; // milliseconds per alpha change
    (framerate).
    var count:Number = 0;
    var alphaPhase:Number = 1;
    var alphaCount:Number = 0;
    function picSwap():Void {
    count++;
    if(count >= (showTime/duration)) {
    alphaCount += alphaPhase;
    img1_mc._alpha = 100-alphaCount;
    img2_mc._alpha = alphaCount;
    trace("img1 alpha: " + img1_mc._alpha);
    trace("img2 alpha: " + img2_mc._alpha);
    if(alphaCount >= 100 || alphaCount <= 0) {
    count = 0;
    alphaPhase *= -1;
    var intervalId:Number = setInterval(picSwap, duration);
    // End of script.
    I am trying to make img1_mc and img2_mc sit inside mc_Mon1.
    So I am thinking that I would need mc_Mon1 to
    "createEmptyMovieClip" named "img1_mc and img2_mc. I thought thats
    what I did with the code but so far my cross fading images just sit
    up on the top left of the screen. Does anyone have any idea how to
    set the target movie clip to load the other movie clips?
    Thanks,
    Kyle

    hi,
    you should make few changes in your code for it to work,
    starting with this:
    instead of - "mc_Mon1 = createEmptyMovieClip("img1_mc", 0);"
    and the
    following line, try - mc_Mon1.createEmptyMovieClip("img1_mc",
    mc_Mon1.getNextHighestDepth());
    mc_Mon1.img1_mc.loadMovie("images/home/image01.jpg");
    and then -
    mc_Mon1.createEmptyMovieClip("img2_mc",
    mc_Mon1.getNextHighestDepth());
    mc_Mon1.img2_mc.loadMovie("images/home/image02.jpg");
    mc_Mon1.img2_mc._alpha = 0;
    and then in picSwap function, it should be -
    mc_Mon1.img1_mc._alpha = 100-alphaCount;
    mc_Mon1.img2_mc._alpha = alphaCount;
    that should do it i think.
    just so you'd learn, in your original code, 'mc_Mon1'
    actually is variable
    reffering to 'img1_mc' (which, if i'm not mistaken, is
    created in _level0),
    but then 2 lines later you overwrite the refference to
    'img1_mc' with a
    refference to 'img2_mc' (which is also created in _level0).
    one more thing which i didn't check - when you declare you
    'intervalId',
    don't u need to use 'showTime' instead of 'duration'?
    good luck,
    eRez
    "kypsul" <[email protected]> wrote in
    message
    news:[email protected]...
    > Hello everyone,
    >
    > I've worked on some code with a little help from some
    people here and I've
    > gotten everything to work. The problem I am having right
    now is getting my
    > cross fading images to sit inside separate movie clips
    that are on my home
    > .swf. The code I have so far is as follows:
    >
    > var showTime:Number = 5000 // milliseconds the picture
    shows at 100%
    > alpha.
    > mc_Mon1 = createEmptyMovieClip("img1_mc", 0);
    > loadMovie("images/home/image01.jpg", img1_mc); // load
    picture from the
    > file
    > directory that your .swf is in.
    >
    > mc_Mon1 = createEmptyMovieClip("img2_mc",
    getNextHighestDepth());
    > loadMovie("images/home/image02.jpg", img2_mc);// load
    picture from the
    > file
    > directory that your .swf is in.
    >
    > img2_mc._alpha = 0; // hide 2nd picture
    >
    > var duration:Number = 30; // milliseconds per alpha
    change (framerate).
    > var count:Number = 0;
    > var alphaPhase:Number = 1;
    > var alphaCount:Number = 0;
    >
    > function picSwap():Void {
    > count++;
    > if(count >= (showTime/duration)) {
    > alphaCount += alphaPhase;
    > img1_mc._alpha = 100-alphaCount;
    > img2_mc._alpha = alphaCount;
    > trace("img1 alpha: " + img1_mc._alpha);
    > trace("img2 alpha: " + img2_mc._alpha);
    > if(alphaCount >= 100 || alphaCount <= 0) {
    > count = 0;
    > alphaPhase *= -1;
    > }
    > }
    > }
    > var intervalId:Number = setInterval(picSwap, duration);
    > // End of script.
    >
    > I am trying to make img1_mc and img2_mc sit inside
    mc_Mon1. So I am
    > thinking
    > that I would need mc_Mon1 to "createEmptyMovieClip"
    named "img1_mc and
    > img2_mc.
    > I thought thats what I did with the code but so far my
    cross fading images
    > just
    > sit up on the top left of the screen. Does anyone have
    any idea how to set
    > the
    > target movie clip to load the other movie clips?
    >
    > Thanks,
    >
    > Kyle
    >
    >

Maybe you are looking for