Flash 5 doesn't have add listener

Browsing the posts, I see a lot of “add listener” code. How do I accomodate this with flash 5? I am trying to have circles deleted or introduced based on either Mousedown or perhaps, a delete key. Can someone help?

Suzie

Sorry dear, there’s no listener capability in Flash 5.0, however the listener creation method is really just to allow you to come up with unique situations to listen for. The regular “onClipEvent(mouseDown)” and “on(press)” in the case of a button will “listen” for those actions.

I’d say that your best bet is to make a movie clip which controls the circles based upon onClipEvent(mouseDown).

What do you know about attaching and duplicating movie clips? Have you done any of that yet?

Thanks for replying.
I am trying to do duplicate movie. FOr some reason I can attach movie, but can’t duplicate. Nothing happens. I did a Math.random function on some dots(if you push a button)and then they scatter around, which is what I want, but what I really would like to do is to press a button, which duplicates dots ONE by ONE. Can’t seem to get my head around this one.

And now I am trying to make a photo gallery, using the photo tutorial by kirupa and this always brings up an error URL message so this is driving me crazy. I think I’ll go back to trying to duplicate movie.

something like

on(release){
dotCount++;
_root.duplicateMovieClip(“dot”,“dot”+dotCount,dotCount);
_root[“dot”+dotCount]._x=Math.random()*600+1;
_root[“dot”+dotCount]._y=Math.random()*400+1;
}

would do the trick.

There are only two things to remember about duplicateMovieClip. A) that there are two methods, one is global (like in my example) and one is an object method, and B) the origional must have an instance name for the method to call to.

Not sure what could go wrong with that. I have a lot more problems with attach myself. The whole linkage thing had me boggled for a while. :slight_smile:

And now I am trying to make a photo gallery, using the photo tutorial by kirupa and this always brings up an error URL message so this is driving me crazy. I think I’ll go back to trying to duplicate movie.

What is the error message that you get?

Here’s what I have:

onClipEvent (load) {
for (i=1; i<=24; i++) {
dot = “dot”+i;
_root.duplicateMovieClip(“dotID”, “dot”+i, i);
_root[dot]._x = Math.random()*200+400;
_root[dot]._y = Math.random()*200+300;
}
}

you gave me a code that says dotCount. Which is supposed to be me entering in my own values for that, like I’ve done above? Still doesn’t work. Also, why for the math.random did you put 600+1? Is it because you were making the starting number 1? The dimensions of the movie? Anyway, I put this code onto a movie clip or the main timeline, doesn’t really matter. but it still doesn’t duplicate 1 by 1, it only puts 24 dots on the stage. ARGH.

About the jpeg error messages—it says Error opening URL. And it repeats infinitely till I close the output message. The relative URL I am typing should be write: C:/My Documents/something,jpg

here is the part of the code that kirupa put up that I don’t get:

this.pathToPics = “”; //I left it blank because shoudl be in the same directory.
// fill this array with pics
this.pArray = [“9192.jpg”, “4142.jpg”];
this.fadeSpeed = 20;
this.pIndex = 0;
loadMovie (this.pathToPics+this.pArray[0], _root.photo);
MovieClip.prototype.changePhoto = function (d)
{ this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {this.pIndex += this.pArray.length;}

she says that the pIndex shoudl fall into the range of the pArray.length–do not get this. have no idea what the modulo is doing there—

what I really want to do is create an array of photos, and make a for loop going through them one after another. shouldn’t this be easy??
well at least I did something right today.

If you or anyone could help with the above that would be great!

SUzie

:nerd: :nerd:

Here’s what I have:

onClipEvent (load) {
for (i=1; i<=24; i++) {
dot = “dot”+i;
_root.duplicateMovieClip(“dotID”, “dot”+i, i);
_root[dot]._x = Math.random()*200+400;
_root[dot]._y = Math.random()*200+300;
}
}

I’m not sure of the reason why that wont work, but I would do your code like so. This was just the way I was taught and I know it works. (so long as there is a movie clip on the main timeline with an instance name of “dotID”.)

onClipEvent (load) {
for (i=1; i<=24; i++) {
_root.duplicateMovieClip(“dotID”, “dot”+i, i);
_root[“dot”+i]._x = Math.random()*200+400;
_root[“dot”+i]._y = Math.random()*200+300;
}
}

you gave me a code that says dotCount. Which is supposed to be me entering in my own values for that, like I’ve done above?

I was just using a count method which would be incrimented every time the button was pressed, giving a new name suffix, and depth for each newly created mc. There are a number of ways of doing that… but they are each for their own purpose. With the for loop above, you provide the i factor so you don’t need a unique incrimenting number each time.

Still doesn’t work. Also, why for the math.random did you put 600+1? Is it because you were making the starting number 1? The dimensions of the movie?

+1 is just to make the number between 1 and say 600 instead of 0 and 599.99. I’m not at all sure it makes a difference in this case. If you were going to move the dots around the board, I know that it would be a good idea to use a Math.round on the y and x coords. I guess in this case I was just resorting to outdated habits.

Anyway, I put this code onto a movie clip or the main timeline, doesn’t really matter. but it still doesn’t duplicate 1 by 1, it only puts 24 dots on the stage. ARGH.

Well a for loop is going to do all of it’s business very quickly. I kind of thought that you wanted to do it by button, hence my button script above. There are other ways of doing it though.

let’s try this.
create a new movie.
place a dot on the stage, select it and hit F8. Make it a movie clip and call it “dot”.

Now with the Action panel open, select dot so that the top of the panel says “object actions”. Then paste this code. (comment tags explain what’s happening.)


onClipEvent(load){
    //I put this and all future dots at 400+ depth so that they wouldn't interfier with any other movie clips on the stage.
    this.swapDepths(400);
    dotCount=400;
    //find the time
    oT=getTimer();
}
onClipEvent(enterFrame){
    //find the time now
    nT=getTimer();
    //compare the old time with the new time if it's more than 1000 clicks the script will fire
    if(nT-oT>1000){
        /*incriment our unique name/depth number*/
        dotCount++;
        //create our movie clip and place it randomly on a 400 by 600 stage.
        _root.duplicateMovieClip(this,"dot"+dotCount,dotCount);
        _root["dot"+dotCount]._x=Math.random()*400;
        _root["dot"+dotCount]._y=Math.random()*600;
        //set the old time to the current time so that we get another 1000 clicks before refiring the script.
        oT=nT;
    }
}

About the jpeg error messages—it says Error opening URL. And it repeats infinitely till I close the output message. The relative URL I am typing should be write: C:/My Documents/something,jpg

I’m really not sure how local jpg’s work… maybe one of the others could answer that. I just place my jpg’s in the same folder as my swf… solves any problem with that sort of thing.

here is the part of the code that kirupa put up that I don’t get:

this.pathToPics = “”; //I left it blank because shoudl be in the same directory.
// fill this array with pics
this.pArray = [“9192.jpg”, “4142.jpg”];
this.fadeSpeed = 20;
this.pIndex = 0;
loadMovie (this.pathToPics+this.pArray[0], _root.photo);
MovieClip.prototype.changePhoto = function (d)
{ this.pIndex = (this.pIndex+d)%this.pArray.length;
if (this.pIndex<0) {this.pIndex += this.pArray.length;}

she says that the pIndex shoudl fall into the range of the pArray.length–do not get this. have no idea what the modulo is doing there—

what I really want to do is create an array of photos, and make a for loop going through them one after another. shouldn’t this be easy??
well at least I did something right today.

If you or anyone could help with the above that would be great!

SUzie

let me think about that. If I can’t figure out their code, I can easily come up with one that will do what you’re asking.

ok------still not working! things I don’t get:::
I want to have <=24 dots eventually clicked onto the stage, by pressing a button. (The button will be one of 10 which will set the color of the dots).
So is the purpose of the swap depths in the above code sort of like “hittest” so the dots don’t collide with each other?
the gettimer—Why do you say “clicks”. don’t you mean like milliseconds? Also, I don’t know why that function is there. I don’t want any time lapse unless determined by the user. So basically I tried the code, didn’t work, changed the event handler to mousedown, hoping that if I clicked down a dot would duplicate–nothing happened.
I’m sorry that I’m not getting this!!

Suzie

OK i got it. I got the duplicate movie code. It’s definitely working now. Now what I have to do is make the button SEt RGB,w hich shouldn’t be too hard. Still having problems with the jpegs though.

I’ll work out a button based script for ya… the above examples are just ideas to work off of, not completed code.

I got the button code now. it goes like this:

on (press) {
i = i+1;
duplicateMovieClip (_root.dot, “dot”+i, i);
target.setRGB(dotcolor.getRGB);
}

This adds a dot and changes its color according to the button pressed.
New problem I am having: I need to have a button to remove a dot one at a time, so the user has control over the number and color of dots.
I am trying to make a function: if you press on a dot(a duplicated movie clip “dot” +i)and press the deletekey at the same time, it removeMovieClip.
Have any idea how to do that? So far I have

//the code on the button within the duplicated clip

if (key.DeleteKey && _this.onPress) {
removeMovieClip(_parent.dot);}

Of course this doesn’t work, i’m thinking maybe the target isn’t right.
Anyway, I want to thank you for being incredibly patient and nice about all my flashing problems. I’m supposed to finish this site in two weeks so I’m just kind of freaking out.

:link: