Creating instances of a movie clip using Actionscript

I have a script that pulls a specified amount of Movie clips
from the library to the stage, and that part of my script works. I
want to add a button that will stop the movie clips but the Movie
clips do not have instance names since they were pulled onto the
stage from my script. I was wondering if anyone had an idea on how
I can do this.

stop();
var _sixSidedDie:Dice;
chooseDice_btn.addEventListener(MouseEvent.CLICK, onClick1);
random_mc.addEventListener(MouseEvent.CLICK, onClick2);
random_mc.buttonMode = true;
function onClick1(event:MouseEvent):void
var diceTotal:Number = parseInt(totalDice_cb.text);
gotoAndStop(2);
for(var i:Number = 0; i < diceTotal; i++)
_sixSidedDie = new Dice();
_sixSidedDie.label = "SixDie" + i;
_sixSidedDie.name = "sixDie" + i;
addChild(_sixSidedDie);
if(i == 0)
_sixSidedDie.frame = 2;
_sixSidedDie.x = 96;
_sixSidedDie.y = 115.7;
else if(0 < i && i < 5)
_sixSidedDie.frame = 2;
_sixSidedDie.x = i * 168 + 96;
_sixSidedDie.y = 115.7;
else if(4 < i && i < 10)
_sixSidedDie.frame = 2;
_sixSidedDie.x = (i - 5) * 168 + 96;
_sixSidedDie.y = 276;
else if(9 < i && i < 15)
_sixSidedDie.frame = 2;
_sixSidedDie.x = (i - 10) * 168 + 96;
_sixSidedDie.y = 438;
else if(14 < i && i < 20)
_sixSidedDie.frame = 2;
_sixSidedDie.x = (i - 15) * 168 + 96;
_sixSidedDie.y = 598;
function onClick2(event:MouseEvent):void
event.target.sixDie0.gotoAndStop(Math.ceil(Math.random() *
6));

Similar Messages

  • How to flip a movie clip using actionscript

    I have a movie clip on the stage facing one way (--->) how
    can I make it face the other way (<---) by flipping it over (not
    rotating it) using action script 3?

    var flipTween:Tween = new Tween(mc, "scaleX", Regular.easeIn,
    mc.scaleX, mc.scaleX*(-1), 1, true);
    should do it I think.

  • Casting a 3d movie clip in actionscript

    Hello All,
    I'm new to flash and actionscripting (i come from the land of ansi c but have traveled extensively). I've created a great animated animated 3d movie clip and want to have them generated on the stage in relation to an xml file. I've gotten this to work with a 2d movie clip but am running into problems casting a 3d object.
    my object (a movie clip - boxContainer with an instance name of boxContainer_mc) is built out of all movie clips in the following way (shown in tree form):
    boxContainer
    -bottomBox
    ---boxFront
    ---boxLeft
    ---boxRight
    ---boxTop
    ---shadowFront
    ---shadowLeft
    ---shadowRight
    ---gradientLeft
    ---gradientRight
    ---gradientFront
    -topBox (this movie clip contains an animation that is controlled through a MouseEvent:Click)
    ---left
    ---right
    ---top
    ---back
    This animates smoothly through flash, but doesn't work when I try to cast the movie clip in actionscript 3 using the following code:
    var boxContainer_mc:boxContainer = new boxContainer();
    addChild(boxContainer_mc);
    When I try to test the swf file I recieve the following errors:
    1046: Type was not found or was not a compile-time constant:boxContainer
    1180: Call to a possibly undefined method boxContainer
    any ideas?

    If this is a library item that you named boxContainer in the library, you need to designate that name as the linkage ID for the movie.  Right click on it in the library, select Linkage from the menu that appears, and in the interface that appears select the Export for Actionscript option (another will be slected automatically).  Be sure your Class name appears as you have it coded and click ok.

  • Dynamic  Instance for a MOVIE CLIP

    Hi Please help me!!!!!!!!!!
    I am creating dynamic Movie Clip using as3, but I don't have
    any idea about dynamic Instance name, please give me some idea that
    how I can assign Instance name for a movie clip.
    I am waiting your reply.
    Thanks
    Sushil Kumar

    You can assign a value to the name property of the MovieClip,
    but refering to the variable name of your MovieClip instance is
    preferable. This code illustrates the difference:

  • How to control movie clips using mause scroller...?

    ....please look
    http://www.nagaoka-id.ac.jp/gallery/gallery.html
    ...how to control movie clips using mause scroller...?

    Hi Ldavinci, I have noticed your posts on that particular
    site before. Just chiming in here... don't be afraid of Flash Help
    menu. There's a wealth of information there and I've found it much
    faster than waiting for a response from the forum. Then if it still
    doesn't make sense, at least you have a basic idea of specifics to
    ask.
    If you search for mouse wheel, you'll see an example under
    the Actionscript 2.0 Language Reference on this topic. That said,
    here's the example:

  • Moving movie clips with ActionScript

    I am trying to move four movie clips with actionscript in a
    circler motion with two buttons, one to rotate the mc’s to
    the left and one button to rotate the mc’s to the right. Here
    is a link to what I am trying to do;
    http://www.us.playstation.com/Lair/
    and it is undrer game features.

    Yes, that's what the code I gave you is intended to do....
    you replace that code with whatever action you need to take to turn
    your movie around.
    I have no idea what your movieclip is doing, but I'm guessing
    by your response that if it was an arrow pointing left to right
    (just an example), you want it to be pointing right to left when
    the left arrow is pressed. If you want an immediate turn around,
    then the simplest way to do that is to have another frame
    containing the movieclip that it moves to where it faces the other
    direction--and to have it appear turned around, from the toolbar
    you select Modify -> Transform -> Flip Horizontal.
    So the movieclip would live inside another movieclip that has
    two frames with stop()'s for each frame. In the first frame you
    would have the subclip facing left to right, and in the second you
    would have it facing right to left. If we call that 2-framed
    movieclip "walker", the code I provided before would
    become...

  • How do I create a play button for movie clip using AS3

    Hello.
    Bit new to this and have been searching the adobe forums and google. I am trying to create a button that will play an imported MovieClip.
    I have a movie clip that I've imported into it's own layer (Layer1) Frame 1.  I've given the MovieClip an instance name of foundationMovie.
    I've created a button and have that on its own layer(Layer2) above layer1, it is also in Frame 1.
    I've added a
    stop (); action to layer2
    The video is not set to autoplay.
    I want the video to start playing when the viewer clicks the button.  I know I've got to put some kind of event listener using AS3 in my timeline somewhere.
    I've found some code and I've been trying to work with it.  I'm sure I've mutilated it beyond usability but this is what I've got.
    stop ();
    player.addEventListener(MouseEvent.CLICK,play);
    function play(event:MouseEvent)
    gotoAndPlay("foundationMovie");
    If someone could point me the right direction or help me with my code I would really appreciate it.  Thanks.

    First, you need to clear up what you are working with... a movieclip and a video are usually entirely different things.
    Next, your code may get you started on your way with some changes.   You shouldn't use "play" as a function name due to there already being a play() method/function in Flash.
    If the movieclip is a movieclip and has an instance name of "foundationMovie", and your button has an instance name of "player" then the following adjusted code would normally work...
    stop ();
    player.addEventListener(MouseEvent.CLICK,playMovie);
    function playMovie(event:MouseEvent)
         foundationMovie.play();

  • Using one instance of a Movie Clip to load Graphics from library

    Hi all,
    another question... How would i go about loading a variable into a movie clip and have it pull different graphics from my library at different spots in the main timeline???
    thanks!
    Patrick

    Hi NED! thank you for all your help so far!!!
    I was wondering about the flexability of loading movies into a movie clip.
    Currently, thanks to your help i am well able to load one movie into a movie "loader" clip, but thought maybe there is a way to load additional movie clips into that same "loader" clip, as i am starting to accumulate several different graphics that i need to have be inside movie clips so that i can make them change colors on the same frame when needed.
    i shot from the hip and tried this code, but didnt have any luck:
    mc_LCD_loader.attachMovie("hilight", "g", 1), ("header", "X", 1);
    mc_LCD_loader.g._x = 0;
    mc_LCD_loader.g._y = 1000;
    mc_LCD_loader."X"._x = 0;
    mc_LCD_loader."X"._y = 1000;
    - - - where "hilight" is the identifier name of a given movie clip and "header" is the identifier of a given movie clip in the same library...
    "hilight" loads fine
    i dont fully understand what "g" means to the identifier...
    i am just unsure of how or if it is even possible to load another MC into the same MC Loader...
    is it possible? if so could you give me a hint?
    thank you!
    - patrick

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

  • Adding thousands of instances of a movie clip

    I am trying to add around 20,000 instances of a single small
    movie clip (HexTile) from the library into a container Sprite using
    actionscript. The problem is it loads immediately and it loads very
    slowly, so I would like to know if there is a way to preload it?
    The class that adds the movie clip library symbol (World) is not
    the document class, nor is it referenced from the document class. I
    have tried dragging an empty sprite linked to World, and I have
    tried exporting it to other frames as well is preloading it as it's
    own .swf...any suggestions would greatly appreciated! The code
    looks like:

    Hi
    I guess you can one thing. add dummy pre-loader before loop
    and then just hide it after loop ;)

  • Can you create a "constructor" for movie clips?

    What I'm doing:
    var this_array[counter] = new monster; //monster is a movie clip
    init_monster(); //set's things like .name, .x, .y, etc.
    What I want to do:
    var this_array[counter] = new monster();
    When I add a "monster"  I then call a function to "initialize" all of it's stats.
    Is there a way in the creation of the object, like with a constructor, where it automatilly does it on 1 line?
    I'm teaching myself and am a little stuck on this part.  If I have to create a "monster class" to do what I want just say so.
    Any simple examples or links to simple examples would be great. Thanks in advance.

    Ok so I've made a class Monster, and I have my movie object Red_Monster
    How would I go about creating the variable so it knows it's both?
    The only thing I can think of is linking them together as a .variable of the other.
    Example:
    var this_monster[x] = new Red_Monster();
    this_monster[x].stats = new Monster();
    It just seems a bit slopy, it would be nice to have this_monster know it's both.  Is there a way to do that?
    (added)
    I've gotten Monster to extend MovieClip, and this is working to use it as a movieclip.
    Currently trying to change the image of the movie clip in code to Red_Monster. Is there a way to do that?
    (added)
    Found how to do it, sort of.  Change the class linkage name to Monster instead of Red_Monster.  I just have to make classes for each movie clip.
    (last add, answer for anyone else)
    Ok the answer is to create a Monster class that extends MovieClip.  Then for each color_Monster they all extend Monster, no other code needed inside each class other then the constructor.

  • How do I move a movie clip in actionscript 3.0?

    Let me start off by thanking Everyone who have help me on Adobe Forums! it helps a ton i am new to actionscript and am trying my hardest to learn it so thank you i cant tell you how it means!
    I have  a movie clip of an acorn named "games" and inside this i have another movie clip named "em_games" when it is click i want to to play out an animation just changing the y coordinates from where the acorn sits in the tree and fall to the ground also when it hit the ground i want it to fire off an animation it has nested inside of it where it cracks open and a piece of paper fly upward where it rests at the top of the screen.i have not moved many objects through actionscript 3.0.
    thanks again to everyone who has helped me out!

    One way to move an object using AS3 is to use the built-in Tween class.  You should look it up in the help documentation for details, or search Google for a tutorial. 
    There are also third party tweening clsses such as TweenLite and Tweener that you could use, though if you are just beginning that might be a lesson better left to more experience since it involves downloading/installing the classes.
    You could also just use an ENTER_FRAME approach to have the y property of the movieclip continually change until it reaches its final value.

  • How to obtain instance name of Movie Clip?

    Hello!
    Is there a way to get the instance name of a move clip once it's on the stage?  In my dress up game, I need to know which items are on the doll in order to keep them visible.  My drag and drop feature uses an array and currentTarget:
    var dragArray:Array = [Doll.Drawers.Dress1, Doll.Drawers.Dress2, Doll.Drawers.Dress3, Doll.Drawers.Dress4];
              for(var i:int = 0; i < dragArray.length; i++)
                        dragArray[i].buttonMode = true;
                        dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
                        dragArray[i].addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp);
    function item_onMouseDown(event:MouseEvent):void
                   var clip:MovieClip = MovieClip(event.currentTarget);
                   clip.startDrag();
    function item_onMouseUp(event:MouseEvent):void
                   var clip:MovieClip = MovieClip(event.currentTarget);
                   clip.stopDrag();
                   if(clip.hitTestObject(Doll.Skins))
                                 //Here's where the problem starts!   ----------------------------------------------  //
                                  trace("It's on the doll!");
    It can successfully run this code.  However, instead of tracing "It's on the doll!", I'd like to turn the currentTarget into it's instance name, which should be "Doll.Drawers.Dress1" etc... and then store that name in an array.
    How would I do this?
    I've looked into e.target.name, but I keep getting errors...

    use the name property of clip (if that's the movieclip whose name you want):
    var dragArray:Array = [Doll.Drawers.Dress1, Doll.Drawers.Dress2, Doll.Drawers.Dress3, Doll.Drawers.Dress4];
              for(var i:int = 0; i < dragArray.length; i++)
                        dragArray[i].buttonMode = true;
                        dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
                        dragArray[i].addEventListener(MouseEvent.MOUSE_UP, item_onMouseUp);
    function item_onMouseDown(event:MouseEvent):void
                   var clip:MovieClip = MovieClip(event.currentTarget);
                   clip.startDrag();
    function item_onMouseUp(event:MouseEvent):void
                   var clip:MovieClip = MovieClip(event.currentTarget);
                   clip.stopDrag();
                   if(clip.hitTestObject(Doll.Skins))
                                 //Here's where the problem starts!   ----------------------------------------------  //
                                  trace(clip.name);  // but that won't be Doll.Drawers.Dress1.  it might be Dress1.

  • Lost ability to move clips using keyboard -and fix

    So suddenly the other day, I could no longer move clips in a timeline using the keyboard. I would select a clip in the timeline and hit (for example) +40 to move the clip down the timeline 40 frames. Didn't matter whether I used the numeric keypad or the keys on the main part of the keyboard. Didn't get any error message or beep. When I hit the plus (or minus key) the little move window would open, I would enter numbers and hit either enter or return. And nothing would happen. I could click and drag on a clip in the timeline without any problems.
    I tried deleting preferences but it didn't help.
    Solution: created new sequence, and copied the contents of the problem sequence to the new sequence and problem solved.

    Thanks for the post Michael.
    I'm curious, you didn't by any chance move up to QT 7.6 did you?

  • Buttons, movie clips and actionScripts

    I've created myself conundrum. In my test movie I have
    created two named frames on the screens timeline (home, box); each
    content frame consists of a movie clip with a button in it
    (home_btn, box_btn). What I'm attempting to do is have the home_btn
    button call the movie in "box" and have the box_btn button call the
    movie in "home".
    If I don't use movie clips the is a simple task,
    home_btn.onRelease = function() {
    gotoAndPlay("box"); }
    but as soon as I place the buttons inside a movie clip the
    navigation ceases to work. I'm assuming I'm getting beaten as
    something very basic, but unfortunately I can't find it.
    Anything thoughts would be greatly appreciated. Thanks
    locoLindy

    Perfect! That fixed the problem. Many thanks for your help,
    I'd have toiled with that for days!
    Again, that's for your help!
    locoLindy

Maybe you are looking for

  • Field Header issue while integrating BO on Bex query

    Hi All I have a integration problem of BO on Bex query.Wondering anyone had a similar problem before. I have a report which has Grant Description, Grant Key and some measures in the report layout. The report also has some additional available fields

  • Windows 2003 R2 Gray Screen Hang on HP DL380 G5 when restarting or shutdown after Nov/Dec 2011 Windows Update

    I've 4 identical HP DL 380 G5 Servers with Windows 2003 R2 Std.  The 4 machines have the same Windows driver version and motherboard BIOS version.  2 have no problem.  2 have problems after Nov/Dec 2011 Windows Update! After running for a few days fr

  • Switching from Entourage to Apple Mail, Address Book and iCal

    I currently use Microsoft Entourage and would like to switch to Apple Mail, Address Book and iCal. I also need to sync with my Palm Tungsten3. Can someone please step me through the process of making this switch? iMac G4 /1.25 256/80 Super   Mac OS X

  • Exciseduty shouldnot roundoff at item level

    Dear mm gurus, i was doing return delivery to vendor with 122 mvt type. i have created outgoing excise invoice J1IS. in j1is bed,ecess,secess are rounding at item level.it should not roundoff at item level but in total it should roundoff to nearest a

  • Backing Beans as session beans

    All the beans on our web application are session scoped beans. Will there ever be any problems due to this? I do not have time to rewrite the beans in request scope. Thanks.