Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# In Flash Mx2004, how do I create more than one shape with Action Script?

Posted on 2007-11-29
Medium Priority
166 Views
The script below will produce one gradient ball 50x50 at x=50, y=50. How do I modify it so that it will simultaneously produce three more  shapes at these locations:
x=50, y=300
x=300, y=50
x=300, y=300

Thanks!
John
``````import flash.geom.*
//

var colors = [0xDCE0B6, 0x000000, 0x000000];
var alphas = [100, 100, 0];
var ratios = [0, 254, 255];
var matrix = {matrixType:"box", x:50, y:50, w:50, h:50, r:(45/180)*Math.PI};
mc.moveTo(50,50);
mc.lineTo(50,100);
mc.lineTo(100,100);
mc.lineTo(100,50);
mc.lineTo(50,50);
mc.endFill();
``````
0
Question by:gabrielPennyback
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 11

Accepted Solution

Tom Ray earned 1400 total points
ID: 20375296
you can use duplicateMovieClip
``````import flash.geom.*
//

var colors = [0xDCE0B6, 0x000000, 0x000000];
var alphas = [100, 100, 0];
var ratios = [0, 254, 255];
var matrix = {matrixType:"box", x:50, y:50, w:50, h:50, r:(45/180)*Math.PI};
mc.moveTo(50,50);
mc.lineTo(50,100);
mc.lineTo(100,100);
mc.lineTo(100,50);
mc.lineTo(50,50);
mc.endFill();

duplicateMovieClip(_root.mc, "mc2", 100);
mc2._x = 0;
mc2._y = 250;

duplicateMovieClip(_root.mc, "mc3", 200);
mc3._x = 250;
mc3._y = 0;

duplicateMovieClip(_root.mc, "mc4", 300);
mc4._x = 250;
mc4._y = 250;
``````
0

LVL 37

Assisted Solution

CyanBlue earned 600 total points
ID: 20375354
Or create a function out of that and call that function with different variables...

CyanBlue
``````function createSphere(__mc:MovieClip, __x:Number, __y:Number, __w:Number, __h:Number)
{
var colors = [0xDCE0B6, 0x000000, 0x000000];
var alphas = [100, 100, 0];
var ratios = [0, 254, 255];
var matrix = {matrixType:"box", x:__x, y:__y, w:__w, h:__h, r:(45 / 180) * Math.PI};

__mc.moveTo(__x, __y);
__mc.lineTo(__x, __y);
__mc.lineTo(__x + __w, __y);
__mc.lineTo(__x + __w, __y + __h);
__mc.lineTo(__x, __y + __h);
__mc.endFill();
}
//
createSphere(mc1, 50, 300, 50, 50);
//
createSphere(mc2, 300, 50, 50, 50);
//
createSphere(mc3, 300, 300, 50, 50);
``````
0

LVL 1

Author Comment

ID: 20439184
Hey, thanks! I'm sorry for being checked out for so long. sibgig's solution worked perfectly right out of the box, so did Cyanblue's, (except for the one missing sphere at 50,50)

The answers were so close in time, and together taught me 2 different ways to explore doing it, I'd like to split up the points woth the majority going to sibgig for getting there first.

Oh and please take a look at my next question which builds on your answers here: http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_23012179.html

Thanks again!

John
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
###### Suggested Courses
Course of the Month9 days, 18 hours left to enroll