Solved

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

Posted on 2007-11-29
3
159 Views
Last Modified: 2010-04-03
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 mc:MovieClip = this.createEmptyMovieClip("grad", 1);

 

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.beginGradientFill("radial",colors,alphas,ratios,matrix);

mc.moveTo(50,50);

mc.lineTo(50,100);

mc.lineTo(100,100);

mc.lineTo(100,50);

mc.lineTo(50,50);

mc.endFill();

Open in new window

0
Comment
Question by:gabrielPennyback
3 Comments
 
LVL 11

Accepted Solution

by:
sibgig earned 350 total points
ID: 20375296
you can use duplicateMovieClip
import flash.geom.*

//

var mc:MovieClip = this.createEmptyMovieClip("grad", 1);

 

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.beginGradientFill("radial",colors,alphas,ratios,matrix);

mc.moveTo(50,50);

mc.lineTo(50,100);

mc.lineTo(100,100);

mc.lineTo(100,50);

mc.lineTo(50,50);

mc.endFill();
 

//additions
 

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;

Open in new window

0
 
LVL 37

Assisted Solution

by:CyanBlue
CyanBlue earned 150 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.beginGradientFill("radial", colors, alphas, ratios, matrix);

	__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();

}

//

var mc1:MovieClip = this.createEmptyMovieClip("grad1", 1);

createSphere(mc1, 50, 300, 50, 50);

//

var mc2:MovieClip = this.createEmptyMovieClip("grad2", 2);

createSphere(mc2, 300, 50, 50, 50);

//

var mc3:MovieClip = this.createEmptyMovieClip("grad3", 3);

createSphere(mc3, 300, 300, 50, 50);

Open in new window

0
 
LVL 1

Author Comment

by:gabrielPennyback
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now