Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




AS2 Random Swf Load - Remove Duplicate



Hi,

I have a banner movie that Im loading a random swf into. When this has finished playing i want to load another random swf in its place. This is working fine other than I am occationally getting the same swf twice in a row.

Can I check if the swf was just loaded and, if so, get another random swf?

I thought I could use something like this but is still has duplicates (maybe because the second random number is the same as the first?)


Code:
// Sets the number of images in the random sequence
var myImageSequence = 6;
var oldmyRandomNumber = myRandomNumber;

// Creates a random number:
var myRandomNumber = Math.floor(Math.random()*myImageSequence)+1;

// Check what last number was
if (myRandomNumber == oldmyRandomNumber) {
var myRandomNumber = Math.floor(Math.random()*myImageSequence)+1;
}



var myImageName = "slides/" + myRandomNumber + ".swf";

// Loads the random swf:
loadMovie(myImageName, this.empty_holder.empty);
Any pointers?



Ultrashock Forums > Flash > ActionScript
Posted on: 2009-01-06


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Random Swf Load - How Do I Remove It?
I am playing with a source from flashkit, that is a banner ad rotator. It works fine and all, but it loads the first file randomly. How do I remove the random function and just make it follow the filelist in the xml?

Here is the AS on the movieclip:

//--------------------------------------------------------------//
// Banner Ad Rotator version 2.0
// Author: Brian Weil
// brian@brianweil.com
// Date: 10/29/2002
//--------------------------------------------------------------//
onClipEvent(load)
{
/* banner_init */
// loads a random banner from
// the bannerData object
banner_init = function()
{
bannerData = bannerXML.firstChild.childNodes;
bCnt = bannerData.length;
curBanner = Math.floor(bCnt*Math.random());
banner_loadNext();
}

/* banner_loadNext */
// loads a the next banner from
// the bannerData object
banner_loadNext = function()
{
curBanner < (bCnt-1) ? curBanner++ : curBanner = 0;
_blank.loadMovie(bannerData[curBanner].attributes.src);

// check to see if the banner has a link
if(bannerData[curBanner].attributes.href != undefined)
{
_button.href= bannerData[curBanner].attributes.href;
_button._visible = 1;
}
else
{
_button._visible = 0;
}

// check for a preferred target window
if(bannerData[curBanner].attributes.window != undefined)
{
_button.window = bannerData[curBanner].attributes.window;
}
else
{
_button.window = "_self";
}

// check for banner specific timeout
if(bannerData[curBanner].attributes.timeout != undefined)
{
timeout = bannerData[curBanner].attributes.timeout*1000;
}
else
{
timeout = bannerXML.firstChild.attributes.timeout*1000;
}
tStart = getTimer();
}

/* banner_ef */
// timer function for banner loading
banner_ef = function()
{
if(getTimer() >= timeout+tStart)
{
banner_loadNext();
}
}

// setup the XML object
bannerXML = new XML();
bannerXML.ignoreWhite = true;
bannerXML.load("banners.xml");
bannerXML.onLoad = banner_init;
}

onClipEvent(enterFrame)
{
banner_ef ();
}

Any help would be GREATLY appreciated.

Duplicate And Remove MC's
I have created a flash movie using actionscript 2.0
when the movie loads, stars burst out from another movie clip in all directions and then the alpha value is pulled down until they are transparent and at that point they are removed,
however i need to know,

how do i detect that an instance of that clip has been unloaded and then duplicate it to go again and again after each time it is 'disolved'

also can a movie clip remove itself from its own enterFrame event?


onClipEvent(load){
//set starting position
this._x=_root.pentagon._x;
this._y=_root.pentagon._y;
//set speed of movement
speed=1+Math.random()*2;
//different trail characteristics
this._alpha = 40+Math.random()*100;
//random size
this._xscale = this._yscale=12+Math.random()*10;
//rotate each star
rotate =Math.random()*300;
//ranodom y fling
yfling=(Math.random()*10-5);
xfling=(Math.random()*10-5);

}


onClipEvent(enterFrame){


this._x+=yfling ;
this._y+=xfling;
this._rotation+=rotate;
this._alpha-=7;
if (this._alpha<=0){
}

}

Duplicate And Remove MovieClip
I've a Movieclip(text) and asign this to it

>onClipEvent(load){
> i=0;
>}
>onClipEvent(enterFrame){
>i++;
>duplicateMovieClip("text", "text" +i, i);
>_root["text"+i]._x=this._x+Math.random()*20;
>_root["text"+i]._alpha=Math.random()*60;
>removeMovieClip(_root["text" +(i-2)]);
>}

When I load the Movie, I can't see any duplicated MovieClip, pls tell me if you know where the problem is

Self-remove Duplicate MC On Its Last Frame
Help! Anyone know how to remove a duplicateMovieClip when it reaches its last frame? My duplicateMovieClips are on key press events, called A1, A2 so forth. I do this by having a counter "sequence" count up from 1 and add to the string "A".

sequence = sequence + 1;
dMC = "A" add string(sequence);
duplicateMovieClip ("spew", dMC, sequence);

And i have to remove the first one first. So, say, i have 5 of the movie clips at one time, i have to remove the first MC first before the second, and so forth. Any help would be appreciated. thanks!

Duplicate/remove MC Problem
i am having difficulty with duplicateMovieClip. I have 12 project buttons, each of which calls a security box (for a name + password) movieclip for a duplicate when pressed. Each security box has a 'close' button. The problems are these:

please see http://www.nomae.com for a demonstration of the following errors. i have made only the first project button (upper left) active for this demo >

1.) the first time a project button is pressed, the duplication works fine and the close button works, too. However, if the same project button is pressed again - no duplication!

2.) if the 'portfolio' button (just beneath the project buttons) is pressed and then the 'projects' button is pressed (thus returning the 12 buttons) the original project button works again!

project button code (which causes a 'security box' to appear):

on (release) {
security_01.duplicateMovieClip("project_01",10);
security_01._x = -283;
security_01._y = 10;
}

the following closes the security box alright:

on (release) {
this.unloadMovie();
}

consequently, the following code did nothing:

on (release) {
this.removeMovieClip("project_01",10);
}

any help is appreciated. thanks.

How To Remove Duplicate Movieclip
I cant seem to remove some duplicate movieclips, and i would really apreciate the help.
On my first frame i have

var t=260;

On the 2nd i got :

_root.objecto._x=t;
this.objecto._y=350+250*Math.sin(t);
duplicateMovieClip(this.objecto,"objecto"+t,t);


t++;

the 2nd frame repeats itself untill a frame 250.
Now what i want to happen is that as soon as it reaches frame 250 it removes all the duplicate movieclips. I tried the removemovieclip function but it didnt work. Any help will be largely apreciated.

Duplicate N Remove Clip Then What
after one remove movie clip then what happen to that clip is it on the stage or som wher else
cause in memory it still shows its exixtence kinldy reply

Duplicate And Remove Movie Clip
I am creating an effect for my website that has a button which, when pressed, duplicates a movieclip. This works fine, but I can't seem to get another button to remove the movieclips that have just been created.

Here is the code I a using:

add new mc's button:

on (release) {
_root.target.Count = _root.target.Count+1;
if (_root.target.Count<50) {
duplicateMovieClip(_root.target.bugs, "bugs"+_root.target.Count, _root.target.Count);
}

delete mc's button:

on (release) {
_root.target.Count = _root.target.Count-1;
removeMovieClip ("bugs"+_root.target.Count);
}

Why does this not work? I have tried loads of slight adjustments to the code and the remove mc action never works. Am I referencing the file wrong?

Any help would be most appreciated.
Thanks,
Shaka

Can't Remove Duplicate Movie Clip
when I creat a MC and have it duplicate itself over and over repeatedly. (example: to create a vortex effect)
I can't make it go away using "remove movie clip" as I would expect.....

How does one make the duplicate movies go away....

thanks

Remove Duplicate Movie Clips
in my movie iv got duplicate movie clips moving around the stage
you click on them and it adds to a score
when the score hits 10 it goes to next scene but the moives are still
playing in the background how do i get ride of them?

Duplicate = Remove Movie Clip
i have a problem that i cant seem to figure out. whenever i duplicate a movie clip, and then i duplicate a different movie clip, the first one dissappears. like, if i have a flower, and i duplicate that. then, when i duplicate a square, the flower goes away.
here is a code for my "ship"

onClipEvent (load) {
sheight = getProperty(this, _height);
swidth = getProperty(this, _width);
speed = 5;
top_border = 1;
bottom_border = 399-(sheight);
left_border = 1;
right_border = 599-(swidth);
i = 1;
b = 1;
l = 1;
e = 1;
maxenemy = 4;
_root.bombfire = false;
}
onClipEvent (keyDown) {
if (Key.isDown(Key.SHIFT)) {
_root.enemy.duplicateMovieClip("enemy"+e, e);
_root["enemy"+e]._x = _root.ship._x + swidth;
_root["enemy"+e]._y = _root.ship._y + sheight;
e++;
}

if (Key.isDown(88)) {
_root.laser.duplicateMovieClip("laser"+l, l);
_root["laser"+l]._x = _root.ship._x + swidth;
_root["laser"+l]._y = _root.ship._y + sheight;
l++;
}
if (Key.isDown(90)) {
if (_root.bombfire == false) {
_root.bomb.duplicateMovieClip("bomb"+b, b);
_root["bomb"+b]._x = _root.ship._x + swidth;
_root["bomb"+b]._y = _root.ship._y + sheight;
_root.bombfire = true;
} else {
_root["bomb"+b].gotoAndStop(2);
b++;
}
}
}

i cant figure out what' going on.
i have attached my fla.
press shift to duplicate the "enemy", then press the space bar to shoot a bullet, then the enemy just dissappears.
thank you all very much.

Remove Duplicate Movie Clips
Follwing is the script I have used for duplicating movieclips:

while (coalcount<2) {
_root.coal.duplicateMovieClip("coall"+coalcount, coalcount);
_root["coall"+coalcount]._x = random(550);
_root["coall"+coalcount]._y = random(500);
coalcount += 1;
}

on time-up it goes to the next scene following the script:
onEnterFrame = function () {
now = getTimer()/1000;
txt = countTotal-now;
p = parseInt(txt);
res = p;
if (p == 0) {
gotoAndPlay("scene 2", 1);
}
};

Th problem is I am not being able to remove the duplicate movieclips. I have tried using the script : _root["coall"+coalcount].removeMovieClip but it doesnot work. Help pls!

Duplicate Mc`s And Remove According To Dynamic Array
Hi there guys,

First off i`m new to this forum and i hope someone can help me / get me on the right way with my (relative simple) problem...

couple of weeks ago i started my own website, http://www.ernst-marten.nl (dutch). It has a feature for visitors to enter their name, once they did it a dude will fall out of the sky and will run to the place where the user clicks in the menu. The nice thing is, that it`s sorta "multiplayer based", when you are running on my site, and another visitor enters my page, he will see you running to the place where you clicked. I also built in a chat-like system in it... users can enter a little string which will be outputted to everyone whos on my site at that moment. There are still a few bugs in it, but here comes my major problem:

the site works with a mysql database when it comes to the "running dudes",
i`m checking every 5 seconds howmany users are logged in. Im calling a php page which outputs all names separated by a comma. I put this in an array and duplicate movieclips from a temporary dudeMC according to the amount of users. When the current amount of users is lower then the updated amount of users (when someone joines) i know what to do, just duplicate movieclips. But what to do if a user leaves... ?
To make it a bit more understandable I have this simple script which represents my problem, the movie had just one frame in it, a input box called "names", a dudeMC, and a process_button.

dude._visible = false;

process_button.onRelease = function() {

temp = name;
current_count = int(name.length);
name = names.split(",");
count = name.length;

//duplicate dudes *count* times
if (current_count<count) {
for (i=0; i<count; i++) {
dude.duplicateMovieClip("dude"+i, "1"+i);
_root["dude"+i].name = name[i];
_root["dude"+i]._x = (i*100);
_root["dude"+i].id = i;
}
} else {
**check which user has left and approach the right duplicated "dudeMC" to set a variable "dead"***
}
};

the problem is, that when a user leaves, i don`t exactly know WHICH user have left... offcourse the names-array will be changed, but i need to approach the duplicatedMC of the user who has left....

well... i know it`s a bit confusing maybe to understand me... i hope someone can help / advise me a bit on this... thanks in advance!!!

MX: Dynamic Duplicate & Remove Of MovieClips
I continue to surprise myself with the things that I don't know ^^

Here's the deal: thanks to the help of many nice people here on the forum, I ended up with a relatively stable code. I have a for-loop that creates instances / duplicates of a movie clip that works like a charm:

Code:
for (pg = 0; pg < arr_tmp.length; pg++) {
var goalRef:String = "goal_" + arr_tmp[pg];
duplicateMovieClip(_root.theBall, goalRef, _root.getNextHighestDepth())
var gmc = eval("_root." + goalRef);
}
Then I position each instance- and I fill an array with the number ("pg"), because:

I also have the option to switch to a different view and at that point I want / need the MoveClips to disappear. So I have a function tied to the switching that goes through a loop for all instances of the movieclip copies (using the array with the IDs from the example above) and remove them.

Code:
for (t2 = 0; t2 < _root.array_all_goals.length; t2++) {
var goalRef:String = "goal_" + _root.array_all_goals[t2];
_root[goalRef].removeMovieClip();
}
...it doesn't work. They stick around.

It *does* work if I use "_visible = false;" instead of "removeMovieClip()"- so the code and phrasing should be right (right?)- but why does one work and the other doesn't?

And is it even advisable to remove the MCs instead of just hiding them until the next time i need them? Your input is very welcome.

Thanks in advance!
~Marcel

Remove Duplicate Movie Problem
ok i have a dot on stage named "dot".

on the "dot" clip i have this.....

onClipEvent (load) {
if (this._name != "dot") {
this._x = Math.random()*1280;
this._y = Math.random()*768;
deedee = Math.random()*100;
this._xscale = deedee;
this._yscale = deedee;
}
}

on a blank clip named "actions" i have this ....

onClipEvent (enterFrame) {
var amount = 100;
for (i=0; i<amount; i++) {
_root.dot.duplicateMovieClip("dot"+i);
}
}


then later on i try to delete all instance of "dot" but there is always one left!!!!!

I tried this ........

onClipEvent (enterFrame) {
var amount = 100;
for (i=0; i<amount; i++) {
_root.dot["dot"+i].removeMovieClip;
}
}

or

onClipEvent (enterFrame) {
var amount = 100;
for (i=0; i<amount; i++) {
_root.dot["dot"+i]._alpha=0;
}
}

anyone??

Compare Arrays And Remove Duplicate Items
I have created two arrays.

var Array1=new Array("a","b","c","d");
var Array2=new Array("c","b");

What if we want to remove items from Array1 which are present in Array2, so that our output will be

trace(Array1);//a,d

Thanks...

Duplicate And Remove Movie Clips Randomly
Hi

I want to make a sparkler button that shows twinkling stars around the button in random positions.

I have made two types of stars (movie clips)

1 - twinkle: this movie clips shows a star appear and disappear with some rotating and alpha channel so the overall effect is like twinkling and revolving star.

2 - same effect star moving on a small curved path.


now I want to use action script for onMouseOver event to duplicate these two movie clips in different X Y positions (very close to each other) with a magical sound. I can do the sound part but not the actionscript part in which i want to duplicate both clips in random positions and then remove them (if that is necessary to free the resources they are occupying) however the stars affect have a fade in and fade out effect so they disappear automatically.

any help is highly appreciated.

thank you.

Help: Multipule Random Positioned Duplicate Random Movie
Does anyone know a way that i can produce a button that when rolled over will duplicate x amount of movies each with random _x and _y positions? Basically i have a movieclip that will
gotoandPlay(math.Round((math.Random()*10)+1)
which randomises that frame that is played. This instance will then do some form of tweening and then gotoandPlay(1) again. I need a script that will then keep generating more duplicate movie clips whilst a button is moused over. i tried the following

on(mouseover){
i = 0;
rand_num = math.Round((math.Random()*29)+1);
while(i<20) {
duplicateMovieClip(_root.movie, "movie"+i,i);
setProperty("movie"+i, _x, _root.movie._x+(rand_num*5);
setProperty("movie"+i, _y, _root.movie._y+(rand_num*5);
i++
}
}

where movie = movieclip name

but this seems to generate all the clips on top of each other @ different depths. I want movies that are all in different positions. Can you help?

DataProvider.merge() Method Seems To Not Remove Duplicate Items
Using the DataProvider class to instantiate UI Components data, I need to merge dataProvider data and remove any duplicate items that may result from the merging process. It is supposed (according to the manual) that the merge method behaves just as i desire, but actually the data is being merged with duplicates. Any hints?







Attach Code

package {

import fl.controls.List;
import fl.data.DataProvider;
import flash.display.MovieClip;

public class dp extends MovieClip {
var data1:Array = [
{label:"item1"},
{label:"item2"}
];

var data2:Array = [
{label:"item1"},// duplicated item
{label:"item3"}
];


var myList:List = new List();

public function dp() {
myList.dataProvider = new DataProvider(data1);
myList.dataProvider.merge(data2);
trace(myList.dataProvider.length);// 4
}
}
}

Search And Remove Duplicate And Consecutive Values In An Array
Hi. I have an array which I am populating as I navigate through the site. Sometimes due to cicumstances apparently out of my control, I end up with two (never more) duplicate values consecutively placed in my array, here is an example:

groceries = ["bananas", "apples", "apples", "oranges"];

I need to run a script at all times that checks to see if this happens, and removes the second duplicate value, as well as it's corresponding key.

How can I do this?

Thank you in advance!

RANDOM DUPLICATE MCs?
I am trying to create the effect of several random boxes, that are very transparent, moving around slowly on the screen - ideally in relation to the users mouse. I am having a lot of trouble however, and the movement often seems to fast. For an example of sort of what I'm talking about check out: http://www.lookandfeel.com, at the bottom of the screen they have these series of lines dynamically moving around.

If I cant get it to go with the mouse, atleast I want to achieve an effect like this. Please Help.
Thanks.

Mr. Jengals

Random And Duplicate Mc
hii to you all
i want to creat a shape that can be MC (with instance) and duplicate it all over the stage in random places. something very simple.. but i dont know how to do it.
thanks
ari -tintoon-

Duplicate Random's
does anyone know a way to get rid of the duplicate random entries that flash tends to create if the random variable is set to a low number? I'm using it to load random images so I need to find a way to eliminate duplicates...

How To Random Xml By Not Duplicate ?
i have XML like this how to random it show by not duplicate until end of record length ???


Quote:





<?xml version="1.0"?>
<!DOCTYPE quiz [
<!ELEMENT quiz (title, items)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT items (item)+>
<!ELEMENT item (question, answer, answer+)>
<!ELEMENT question (#PCDATA)>
<!ELEMENT answer (#PCDATA)>
<!ATTLIST answer correct (y) #IMPLIED>
]>
<quiz>
<title>Trial Quiz</title>
<items>
<item>
<question>____ is a car.</question>
<answer correct="y">This</answer>
<answer>That</answer>
<answer>These</answer>
</item>
<item>
<question>____ is a boy.</question>
<answer correct="y">This</answer>
<answer>Those</answer>
<answer>That</answer>
</item>
<item>
<question>____ is an orange.</question>
<answer correct="y">That</answer>
<answer>Those</answer>
<answer>This</answer>
</item>
<item>
<question>____ is a telephone.</question>
<answer correct="y">That</answer>
<answer>This</answer>
<answer>Those</answer>
</item>
<item>
<question>____ are dogs.</question>
<answer correct="y">These</answer>
<answer>Those</answer>
<answer>This</answer>
</item>
<item>
<question>____are birds.</question>
<answer correct="y">These</answer>
<answer>This</answer>
<answer>Those</answer>
</item>
<item>
<question>____are pencils.</question>
<answer correct="y">These</answer>
<answer>Those</answer>
<answer>This</answer>
</item>
<item>
<question>____are rulers.</question>
<answer correct="y">These</answer>
<answer>This</answer>
<answer>Those</answer>
</item>
<item>
<question>____ are erasers.</question>
<answer correct="y">These</answer>
<answer>Those</answer>
<answer>This</answer>
</item>
<item>
<question>____are boys.</question>
<answer correct="y">These</answer>
<answer>This</answer>
<answer>Those</answer>
</item>
<item>
<question>____are bags.</question>
<answer correct="y">These</answer>
<answer>Those</answer>
<answer>This</answer>
</item>
<item>
<question>____are horses.</question>
<answer correct="y">These</answer>
<answer>This</answer>
<answer>Those</answer>
</item>
</items>
</quiz>

Remove Clips From Stage In Random Order
Hello,
I have 6 letters accross the stage on layer 1. I then attach 6 instances of a movie clip from the library accross the stage to cover them using a for statement, so far so good.

Now I want to randomly remove them 1 by one. Any ideas? Here is what I have so far..


ActionScript Code:
var main:MovieClip = this;
var numOfLetters:Number = 6;
var nInterval:Number;
var randomRemoval:Number;
//attach 6 instances to the stage 50 px apart to cover letters//
for (i=0; i<numOfLetters; i++) {
    cover = main.attachMovie("cover", "cover"+i, i);
    cover._y = 50;
    cover._x = i*50;
}
//remove the 6 cover instances 1 at a time from the stage//
nInterval = setInterval(remove, 1000);
function remove() {
    randomRemoval = Math.round(Math.random()*numOfLetters);
    cover/*??*/.removeMovieClip();
}

cheers for any suggestions in advance.

---

Duplicate MC And Set Random Position
Hi All,

Need some expert help.

I need to duplicate a MC five times, and set its position on the X axis randomly.

Towards this end i used this script:

Code:
duplicateMovieClip ("mark", "mark1", -1);
duplicateMovieClip ("mark1", "mark2", -2);
duplicateMovieClip ("mark2", "mark3", -3);
duplicateMovieClip ("mark3", "mark4", -4);
duplicateMovieClip ("mark4", "mark5", -5);
setProperty ("mark",_x,random (550))
setProperty ("mark1",_x,random (550))
setProperty ("mark2",_x,random (550))
setProperty ("mark3",_x,random (550))
setProperty ("mark4",_x,random (550))
setProperty ("mark5",_x,random (550))
The script works perfectly, but unfortunately, at times the duplicated clips overlap one another. How do I ensure that there will be no overlapping of the clips at all?

Thanks for any inputs

Duplicate And Random Animation
Hi

I have a box (130 wide, 432 high) sitting on the hard left of my page. I want to get the box to populate line by line from the left, so ideally I would have 216 lines (lines are 2 high) zooming in from the left side. So I assume I would use duplicate move clip to save animating so many lines, and I also want the 216 lines to come in at different speeds or times, but eventually all end up as a solid box.

I can duplicate the lines OK

thistimeline = this;
for(i = 1; i<100; i ++){
lined_mc.duplicateMovieClip("lined" + i + "_mc", i, lined_mc)
thistimeline["lined" + i + "_mc"]._y += (i);

But getting them to move like I have described has me stumped...

Any ideas. Thanks.

Random Bits? Duplicate MC?
I'm trying to create an application that will allow the user to fill an area with a variety of materials by dragging a scrollbar. I've got a rough version at:
http://www.designdevelopdeliver.com/pieces.htm

Two problems:
1)I can't mask the duplicate clips. I've masked the layer that the original clip is on, but none of the duplicated clips are masked.

2)And the BIG one, I need the slider to fill the circle with randomly SHAPED portions of the movie clip and I can't figure out how to randomly shape the pieces...any ideas???

TIA...

Help - Duplicate And Random Placement
Hi,
Im trying to get the correct syntax for this...,
Could anyone help....deadline looms ahead for me.
Basically a bubble mc called bbl_1 on the root timeline gotta be duplicated in random _x positions while the _y coordinate stays the same. It duplicates allright but, no random positioning.

The code:

onClipEvent (mouseDown) {
_root.main.bbl_1.duplicateMovieClip("bbl_"+"x", x);
_root.main["bbl_"+x]._x=random(400);
x++;
}

HELP please!

Random+duplicate+width.. Help Please?
hi.. i have a little problem with a script i found...


PHP Code:



for (i=0; i<30; i++) {
    newBall = mask_mc.duplicateMovieClip("mask_mc"+i, i);
    newBall._x = Math.random*600;

    newBall.targX = Math.random()*600;

    newBall.i = 0;
    newBall.rand = Math.random()*50;
    newBall.onEnterFrame = function() {
        this.i++;
        if (this.i>this.rand) {
            this.targX = Math.random()*600;

            this.i = 0;
            this.rand = Math.random()*50;
        }
        this._x -= (this._x-this.targX)/5;

    };





Problem is this does'nt seem to work in a mc with a mask.. it works i know that cos if i unmask my layer it starts perfectly but as soon as i make the layer mask again it stops working....

how come and how do i fix this?

Ps, and wile your at it.. how do i add a random width section to this script?

Random No Duplicate Pics
I'm using a slideshow in this site gallery but I want to integrate a random to display. How to make a random display without any duplicate pics??

ex: I have 5 pics in xml file, then they inserted in an array. From there, i want to display them randomly without any duplication

thanks in advance

Using A Loop To Duplicate And Random X Pos
Hi people, got some code working to duplicate a movieclip, but what I'd really like to do is obviously randomise the movieclip's x position so that it spreads across the stage, rather than stacking in the same position as it is now. Any clues greatly apprciated

julie
x


Code:
for (i=1; i<11; i++){

duplicateMovieClip("alien", "alien_new_"+i, 22-10, i);

}

[FlashCS3-AS2] Duplicate Mc, Random _y Help
Greetings - I've been prowling and found a start for what I'm trying to do. Need help refining it. I pilfered the snowconfetti.fla AS and have modified it, but not quite there.
I want to attach a MC at a random _y location, and move it left to right across the stage, at random speeds. Then when it goes offstage, a new one is generated.
Right now the interval loads a new clip at 8 sec. no matter where the current clip resides on stage, so I'm sure that is wrong.


Code:
function brand() {
clip = attachMovie("brand_mc", "brand"+i, i);
clip._x = -50;
clip._y = Math.floor(Math.random()*640);
clip.xspeed = Math.random()*4-1;
clip.onEnterFrame = move;
i++;
if(i > 20){
clearInterval(myInterval);
}
}
function move() {
this._x += this.xspeed;
if (this._x>1100) {
this.removeMovieClip();
brand();
}
}
myInterval = setInterval(brand, 8000);

Thanks much for the help!

Random+duplicate+width.. Help Please?
hi.. i have a little problem with a script i found...


PHP Code:



for (i=0; i<30; i++) {
    newBall = mask_mc.duplicateMovieClip("mask_mc"+i, i);
    newBall._x = Math.random*600;

    newBall.targX = Math.random()*600;

    newBall.i = 0;
    newBall.rand = Math.random()*50;
    newBall.onEnterFrame = function() {
        this.i++;
        if (this.i>this.rand) {
            this.targX = Math.random()*600;

            this.i = 0;
            this.rand = Math.random()*50;
        }
        this._x -= (this._x-this.targX)/5;

    };





Problem is this does'nt seem to work in a mc with a mask.. it works i know that cos if i unmask my layer it starts perfectly but as soon as i make the layer mask again it stops working....

how come and how do i fix this?

Ps, and wile your at it.. how do i add a random width section to this script?

Duplicate Random Numbers
I am loading random images into 3 different blank MCs. I've got the randomization down, but I was wondering, how can I check to make sure that the 3 random numbers aren't the same? I could simply divide the images up into different names or folders and that way I know the 3 random images wouldn't be the same image, but how could I do it with actionscript?



ActionScript Code:
num = random(36)+1;
num2 = random(36)+1;
num3 = random(36)+1;
loadMovie("sidebar/image"+num+".jpg", "_root.image1.loadit");
loadMovie("sidebar/image"+num2+".jpg", "_root.image2.loadit");
loadMovie("sidebar/image"+num3+".jpg", "_root.image3.loadit");
stop();

How Do I Remove Random Function From This Dynamic Image Gallery?
Hi, I'm new here and new to actionscript. I am trying to remove the random funciton from this script and to add a button which simply allows the user to click forward through the images in order rather than randomly. I've tried a bunch of things but am going nowhere...any help would be greatly appreciated...


MovieClip.prototype.scaleTo=function(m){
with(this){
_xscale=_yscale=100;
var p=new Object({H:_height/m._height,W:_width/m._width});
p=(p.H>p.W) ? p.H : p.W;
_yscale=_xscale=100/p;
_x=m._x-_width/2, _y=m._y-_height/2;
}};

Number.prototype.Rnd=function(){
var num=this
var newRnd=Math.round(Math.random()*(num-1)-(-1));
while((newRnd==this.Rnd.old)||(newRnd==this.Rnd.va ryold)){
newRnd=Math.round(Math.random()*(num-1)-(-1));
}
trace( this.Rnd.veryold+ " "+this.Rnd.old+" "+newRnd);
this.Rnd.veryold=this.Rnd.old;
this.Rnd.old=newRnd;
return(newRnd);
};

//need some pictures Picture1.jpg, Picture2.jpg, Picture3.jpg
//and a movieClip that is _visible==false to scale to "myMask".
//and a movieClip to act as a button

_global.noPictures = 5;

assessLoad = function(clip, loadFunc,myMask) {
if ((clip.getBytesLoaded()/clip.getBytesTotal() == 1)&&(clip._width>4)) {
clip[loadFunc](myMask);
clip._alpha=1;
clip.onEnterFrame=function(){
if(this._alpha<100){
this._alpha+=5;
} else {
this._alpha=100;
delete this.onEnterFrame;
}
}
clearInterval(loadInterval);
}
};
newPic_btn.onRelease=function(){newPic(this,"clip" )};
function newPic(clip){
_root["clip"+this.status].swapDepths(50);
this.status=!this.status;
var genNum=noPictures.Rnd(noPictures);
var pic = "Picture"+genNum+".jpg";
trace(pic);
var clip=_root.createEmptyMovieClip("clip"+this.status *1,100);
clip._x=1000;
clip._y=1000;
clip.loadMovie(pic);
if(loadInterval!=undefined){
clearInterval(_root.loadInterval);
}
_root.loadInterval = setInterval(_root, "assessLoad", 40, clip, "scaleTo", _root.myMask);
};
size.onPress=function(){
this.startDrag();
this.onEnterFrame=function(){
rescale(this,_root.myMask);
}
}
size.onRelease=function(){
this.stopDrag();
rescale(this,_root.myMask);
this.onEnterFrame=null;
}
function rescale(mc,masc){
masc._width=2*Math.abs(mc._x-masc._x);
masc._height=2*Math.abs(mc._y-masc._y);
s=_root.newPic.status;
_root["clip"+s*1].scaleTo(masc);
_root["clip"+!s*1].scaleTo(masc);
}
rescale(size,_root.myMask);
newPic(newPic_btn,"clip");

Duplicate Random Numbers (preventing)
Sorry for yet another thread..........I seem to have planned a large scripting game before knowing my full coding.........

Anyhow......



I have a dynamic textbox named "Output" that displays random quotes. These are chosen randomly and that all works fine. My problem comes when the same quote is randomly chosen...........it overwrites the quote in "Output" and as a result, turns the text invisible.............I think this is down to an overwriting issue that turns same colour pixels white !?!


Anyhow, I tried code to choose a different number so as to try and prevent this issue yet it isn't functioning. Can anyone enlighten me as to what I'm doing wrong, or if there's a better/safer method of achieving this.

Basically I don't want the same quote printed twice in a row.


My code from frame 1: (Where "Correct" is an array with quotes duly allocated)
----------------------------------

quotenumber = Math.ceil(Math.random() * Correct.length);

-------------------------------------------------------


My code from frame 2:
-------------------------------------

_root.TempQuote = Correct[quotenumber];
if (_root.TempQuote == _root.LastQuote){
gotoAndPlay(1);
}
else {
_root.LastQuote = Correct[quotenumber];
Output = Correct[quotenumber];
GoodPlay.attachSound(GoodSounds[quotenumber]);
GoodPlay.start(0, 1);
TotalScore = TotalScore + 1;
}

-----------------------------------------------


Any ideas ?

Array And Duplicate Random Pictures
hi there all, hope someone can help,

i am displaying random pictures in a movie. each time the
user clicks a square on the screen an image/movieclip appears.
my problem is that at the moment 2 or more of the same image/movieclip
can appear on the screen at the same time and i do not want
that.
i have tried adding each number representing the random
movie to an array and then doing a check to see if that number exists in the array. if it does exists this means the image/movieclip
is already displayed on the screen so do not show it and generate
a new number and so forth. i am receiving all the necessary
values perfectly.
my code to do the check is as follows :

i = 0;
_root.myArrayPhoto.push(randMov);
outerArraylength = _root.myArrayPhoto.length;

for(i=0; i <= outerArraylength; i++) {
if ((_root.myArrayPhoto[i] == randMov)) { //check if movie exists
gotoAndPlay(1);//goto first frame and to random func again
}
}

//else loop finished so
//movieclip does not on screen so show it :
loadMovie "swf/photo"+randMov+".swf", "_root."+_root.thisWhich);
gotoAndPlay(1); //goto first frame and start again


thanks!

Duplicate, Random Placement With Easing
doesn someone know how to recreate the initial load of the rectangles that this site uses?
http://www.ag.raise-media.com/and_gaiv.htm

i took a shot at it from scratch and its not working out

ActionScript Code:
div = 4;
i = 0;
while (i<20) {
    duplicateMovieClip("clip", "clip"+i, i);
    endX = random(400);
    endY = random(400);
    _root["clip"+i].onEnterFrame = function() {
        this._x += (endX-this._x)/div;
        this._y += (endY-this._y)/div;
    };
    i++;
}

it appears as the every single duplicate of "clip" is receiving the same x and y coords and i dont know how to assign separate x,y to each individual clip

i could be going about it all wrong so if someone has another solution it would be greatly appreciated.

thanks
-a

Duplicate By Random And Remain On Stage
Hi,
I got a project containing 4 movieclips to be duplicated by random and placed on a certain position on stage.

all movieclips are placed on top of on another.
the problem is: already placed movieclips don't remain on stage - they get replaced by the next movieclip duplicated in.

How can I make the already placed clips stay on the stage?

Please review to my attachement.

Thanx guys, you are my last resort!

MC Duplicate With Random Location In Set Range
Hey all!

Im having a bit of a problem with duplicating a movieclip.
Im an AS noobie, so dont kill me for stupid mistakes lol.
Heres what im trying to do:
I have a button, when the <Insert> key is pressed and if the variable money at root is higher or equal, then make the variable "vpill" equals 1 and duplicate the MC "pill".
Heres the code i have for that:


Code:
on (keyPress "<Insert>"){
if (_root.money >= 1000){
_root.vpill = 1;
_root.money -= 1000;
duplicateMovieClip(_root.pill, "pill"+1, _root.pill);
}
}

As for the MC "pill", what i want is if the variable "vpill" equals 1 then at a random location (in a set range), place the mc, and if hitTest is true with "player" then _root.speed -= 1; make "vpill" equal 0 and remove the duplicated MC.
Heres the code i have on "pill" MC:


Code:
onClipEvent (load) {
randomNum=function(Minimum,Maximum){
return Minimum+Math.random()*(Maximum-Minimum);
}
if (_root.vpill == 1) {
pillx = randomNum(220, 480);
pilly = randomNum(70, 330);
this._x = pillx;
this._y = pilly;
if (this, hitTest(_root.player)) {
_root.speed -= 1;
this.removeMovieClip();
_root.vpill == 0;
}
}
}

NOTE: Variables are all placed in the root.

Thx in advance!
If u dont understand something, feel free to ask. THX!

Duplicate By Random And Remain On Stage
Hi,
I got a project containing 4 movieclips to be duplicated by random and placed on a certain position on stage.

all movieclips are placed on top of on another.
the problem is: already placed movieclips don't remain on stage - they get replaced by the next movieclip duplicated in.

How can I make the already placed clips stay on the stage?

Please review to my attachement.

Thanx guys, you are my last resort!

DUPLICATE,ANIMATE,ALPHA,SIZE All Random
How do I make a movie clip duplicate 50 times on a stage of 800x600 and animate each randomly on the stage, each starting from on point and all spreading randomly across the stage togather.. Also each movie clip should scale to 1% and the alpha sholud fade out to 0%....phew...

and can anyone give me the script for this in Flash 4.0


very very urgent...

Thanks in advance

Duplicate Mc Movement/random Start Times
I've got an mc of a animal that i'm using in the background of a site. at the moment 5 of these mc's move across the screen inside another mc, using this code on the mc:


Code:
onClipEvent (load) {
//set initial x pos of clip
this._x = 0;
}
onClipEvent(enterFrame){
//this moves our clip 1 pixel to the right every frame
//up to a certain point
if (this._x<670)
{
this._x+=0.08;
}
if(this._x == 670){
wait+=1;
// Wait 100 frames before resetting things
if(wait>100){
//Reset actions here
wait=1;
this._x = 0;
}
}

}



This is all good but the 5 animals all walk in tandem which gives an unnatural look to it all. I was thinking that it would be better to just have one mc and duplicate this where needed. a random number between 2 and 5 could be chosen and this number of animals would move across the screen having all started at random times (but within confines so that they still move as a group. i would also want the delay to remain so that the effect remains subtle.

Any hints on the actionscript would be much appreciated.

Thanks.

A For Loop With Random Vairalbes - How Not To Get Duplicate Results
Hey All, I have a loop that runs through 5 times and each time calls a function that puts two variables together randomly:

CODE:

myname = [];
for (i=0; i<4; i++) {
createRandomName();
trace(diarytextvar);
myname[i] = randomname;
trace(myname[i]);
}

randomname is a random match of two variables (ie., ShortDog, CrazyChicken, etc.). How can I check if a duplicate has occured and if so run the function again. So that each of my variables (myname0, myname1, myname2, myname3, myname4) are not duplicates?

Thanks in advance, Dvl

Getting Duplicate Item From Range Of Random Numbers
hi everyone,

Im trying to create a list random numbers from 1-30 but only 10 will appear. but i also need to make sure that the list of random numbers will not have duplicates (eg 1,1,20,14,3,28,4,1,18,21). I had the thought of using an array to store the list of numbers but im stuck with how to properly use an if..then to check if the same number has already appeared.

Sorry if this was asked before but im just really confused with how to extract the contents of the array and see if one of them already appeared. I've attached the code so anyone can see what went wrong with it.

Anyone's help is greatly appreciated. Thanks everyone!

_scriptRookie


Code:
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
return randomNum;
}

var myArray:Array = new Array();

for (var i = 0; i<9; i++) {
var n:Number = randRange(1, 30);
trace(n);
myArray.push(n);
for (var j = 0; j<myArray.length; j++) {
if (myArray[j] == n) {
myArray.pop();
var n:Number = randRange(1, 30);
}
trace(">> "+myArray[j]);
}
}

Duplicate Grid Of MovieClips With Random Starting Times
Need a bit of help here, if anyone can show me the right path?

I need to create a regular grid of movieclips using duplicatemovieclip, which cover the screen. let's say, an animated square that fades from white to black. I then need these movieClips to start at random times so that the eventual state is of the whole screen with a grid of black squares. Kind of like asped up film of lights going out on a skyscaper. Sort of.

Any ideas?

cheers people...

PLEASE HELP - URGENT Load Random Swfs From Individual Random Sets
I have two target mcs I would like to load different random swfs into

I have eight folders (a-h), each with 12 swfs (001-012)

I need to load a random swf (001-012) from a random folder (a-h) into the "card1" mc

I have figured out how to specify which one I want:

loadMovie("a/a001.swf","card1")
stop();

however, I need it randomized....

then, I need to load another random swf into my "card2" mc (001-012) from another random folder (a-h, ...except for the folder from which the first swf was loaded)

can somebody please help??????

Load And Remove MC
Ok
I have some movie clips I want to make visable by clicking on a button. I know it has something to due with a true false statement but I just can't figure it out. I saw it somewhere before that you can use alpha to make it invisable or visable.

So basically a button on the main level will make it visable and a button in the clip itself will make it disappear.

Do I need to make an empty clip and just load into that?

Or can it be just a funtion?

It's not being load externally.

Help please

Copyright © 2005-08 www.BigResource.com, All rights reserved