dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Help Needed: How to create multiple objects with same properties

  1. #1
    Junior Member
    Join Date
    Dec 2005
    Location
    Washington State
    Posts
    5

    Help Needed!!!: How do I create multiple objects with same properties

    I need to know how to create multiple objects with same properties and that can be collectively referenced to in ActionScript. For example, if I want to create a mc that bounces off of any one of 20 different other mc's, how would I do that without writing the code for each instance name. It's a problem that's been annoying me for a while now. I would love some help. Thanks.
    Last edited by randRange; 12-03-2005 at 08:45 PM. Reason: minor edit

  2. #2
    Junior Member
    Join Date
    Dec 2005
    Location
    Washington State
    Posts
    5

    Would attach movie work?

    Can anyone tell me if attach movie would work for this and how to do it?

  3. #3
    Member
    Join Date
    Nov 2005
    Posts
    32
    I dont think you need different instane name for something like that. Just put in the code for one instance and copy and paste the instance.

  4. #4
    Junior Member
    Join Date
    Dec 2005
    Location
    Washington State
    Posts
    5

    That doesn't work

    If you give two objects the same instance name, one of them (the copy) does nothing.

  5. #5
    Registered Deviant
    Join Date
    Sep 2004
    Location
    Cornelius, OR, USA
    Posts
    280
    Depends on what properties you want to copy. The attached code sample uses an object to hold the values we want all of our "balls" to hold. For this example, just rotation and y coordinate, we alter the x and alpha on each iteration so we can see the different balls.
    Code:
    stop();
    
    // All attached movies will be at 100 down and rotated 45 degrees
    var o:Object = new Object();
    o._y = 100;
    o._rotation = 45;
    
    for( var i:Number = 0; i < 10; i++ ) {
    	// so we can see the difference, we'll space out each ball
    	o._x = i * 30 + 15;
    	// and change the alpha
    	o._alpha = 10 * ( 10 - i );
    	// attach the new movie, notice how we pass our Object 'o' at the end?
    	this.attachMovie( "ball", "ball" + i, this.getNextHighestDepth(), o );
    }
    If you can read this, you're in the right place.

  6. #6
    Junior Member
    Join Date
    Dec 2005
    Location
    Washington State
    Posts
    5

    Thanks for the help

    I figured out how to do it finally. I used used an array to store the instance names of objects.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center