Another infinite menu question :)

i dont know what the deal is… but this is what got it to work

[AS]
movieWidth = 60;
for (i=1;i<=9;i++) {
this.createEmptyMovieClip(“movies”+i,i);
loadMovie(“chattingup.jpg”,“movies”+i);
setProperty(“movies”+i, _x, (i*movieWidth));
}
stop();

[/AS]

can some one explain to me the difference with the earlier script. and why do i HAVE to use setProperty? anyways i can now get on with what i set out to do… thanks for your help.

P.S. If some one could also explain to me why I get the gaps as explained in one of my earlier posts in the same thread i’d be grateful. it can be viewed at http://www.geocities.com/ckatre/scrollingmenuphoto.swf. YOu may have to cut and paste the link due to yahoo’s policy of disabling links or something.

Oh, that previous mistake was my fault, the code should have been…

[AS]movieWidth = 60;
for (i=1;i<=9;i++) {
this.createEmptyMovieClip(“movie”+i,i);
this[“movie”+i].loadMovie(“image1.jpg”);
this[“movie”+i]._x = i*movieWidth;
}
stop();[/AS]

And that link doesn’t work for me (yes I am fully aware how to access a geocities link like that, we get many of them here)

hey lostinbeta

just thought i’d let you know the above endeavor is a success … .still have to code in the array part. but the difficult part is over (i think so) you can see the site here (its incomplete - just the home and photo gallary buttons are active) and a click on the infinite image button will bring up another window linked to yahoo.

Just have to create thumbnails and associte them with their respective jpg’s. thanks mate for your help.

cheers

I am glad to see you got it to work.

That navigation on the site looks like a script I posted in another thread :slight_smile:

so it is!!!

I thought it was cool. There will be a credits section which i am going to make and you are going to be there. :wink:

cheers

LIB… looks like i am stuck again. Knowing how much dear dynamic event handlers are to you, i cometh to seek thou assistance. =) I am attaching the zipped fla file. I am kind of wacked out and cant think staright any more.

Two things. If I run the fla using ctrl-Enter then the thumbnails loaded do not seem to act as buttons. (cant see the mouse changing to the hand cursor) But when I load this file into the main movie, it does and becomes clickable. Havent been able to explain this.

second thing is, it always picks up the file from the default option of the switch/case statement. me thinks the parameters are not being passed correctly ( the value of i). what am i doing wrong? Have included certain comments in the file itself.

The swf can be viewed at the photo gallary section at http://www.geocities.com/ckatre/

i think the mistake i was doing was coding the dynamic event handler of onRelease within the EnterFrame. I took it out. and now I cant see the default image too. :slight_smile:

That got me to think - since I am looking for the "i"value where in the world am going to find it? the value of i would be the last value once it finishes the loop.

So I need to find out the name of the button instance and use that as a variable to switch!

back to basics it is for me!

I didn’t check out your file, but I think I know what your doing wrong.

Add the onRelease dynamic event handler inside the for loop. Something like…

[AS]movieWidth = 60;
for (i=1; i<=9; i++) {
mc = this.createEmptyMovieClip(“movie”+i, i);
mc.loadMovie(“image1.jpg”);
mc._x = i*movieWidth;
mc.newVariable = i;
mc.onRelease = function() {
trace(this.newVariable);
};
}
stop();[/AS]

Trace is used for testing to make sure variables/information is passed correct, the value of the variable will appear within the output window during testing when the trace is called upon. Which in this case would be onRelease of the clip.

So what we did in the script above was dynamically created a variable into each duplicated clip and set it to the current value of “i” at that time in the for loop. Then we can use that inside the onRelease handler.

As I mentioned earlier it does not recoganize the movie clips as buttons if there are any button event handlers within the for loop. So I cant click on these buttons to trace them. If I do not put button event handlers into the for loop then in the main movie they become clickable.

But i tried what you said. And when I call the swf from the main movie, those buttons become un-clickable. Remove the event handler from the for loop and voila … they can be clicked in the main movie!

in either case from the scrollmenu…swf file those images cannot be clicked on. i have to use the main file to test this one.

Did I mention i use
[AS]this[“movies”+i].trackAsMenu = true;[/AS]
to change the movie clips into buttons.

Well i removed them and tested - with the same result.

You caught me just in time, I was about to call it a night.

I looked at the .fla, and it won’t run unless I have all the images. Without them it throws: “Error opening file:///…” so I can’t really test it. But I did look at the code.

It looks to me like you’ve got a couple extra steps you don’t need.

First is the “trackAsMenu” stuff. All you need to turn a movieclip into a button is add a button event (e.g. onRelease, onRollOver, etc.) to the movieclip. This is a normal movieclip:


myClip_mc

but when I add some event to it, it suddenly gets a hand cursor when my mouse passes over it and responds when I click it:


myClip_mc.onPress = function() {
  trace("movieclip-button has been clicked");
} // end myClip_mc.onPress()

This is all you need to turn your clips into buttons. trackAsMenu has a specific purpose: it’s used when you click one button and another expands off the first. Normally when you release the mouse click, both buttons go back to the “up” state, but if they are trackAsMenu, they stay in the “down” state.

The second thing you probably don’t need is the switch function that you’re using to load the images. You’ll notice that I simply added an “onPress” to the movies in the initial for-loop, and inside that “onPress” handler I call loadPicture directly. This should solve the problem you were having wondering how to get the right value of “i”, and it will make these clips into buttons.

Like I said, I haven’t tested this because I can’t get your .fla to run without the images, but this is always the way I do it and it’s much simpler this way. Give the .fla I posted here a try, it might work.

Hopefully this gives you some ideas or fixes something. I’m off to bed.

Ah, I’ve been typing that last post up and it looks like lostinbeta already said this stuff. Yeah, that’s two people saying the same thing now. . . we must be onto something.

It’s probably a path problem that is causing the button problems . . . i.e. it won’t work when you load it into the main movie because you have a path that’s wrong somewhere.

thanks aurelius. u really must like actionscripting :slight_smile: cant imagine myself debugging scripts when i am tired and ready to hit the sach.

actually, aurelius, it works only when called from the main file but not on its own. there are 2 files: main.swf & scroll.swf. If I run scroll .swf in the explorer the buttons are to be enabled. However if I call scroll.swf from main.swf, the buttons are enabled.

This is turning out to be a hell of project and more than I bargained for ;). Two days in a row no final output in sight. Such is coding, eh!

This is what worked when called from the main file. mc cant be clicked from this file.
[AS]

for (i=0;i<=9;i++) {
mc = this.createEmptyMovieClip(“movies”+i,i);
mc.loadMovie(“image”+i+".jpg");
mc1 = this.createEmptyMovieClip(“doubleM”+i,i+10)
mc1.loadMovie(“image”+i+".jpg",“doubleM”+i);
mc._x = (imovieWidth);
mc1._x = (i
movieWidth + 600);
this.onPress = function() {
loadPicture(i);
};
}

loadPicture = function(a) {
_parent.createEmptyMovieClip(“imageLoader”, 10);
_parent.imageLoader.loadMovie(“picture”+a+".jpg");
_parent.imageLoader._x = 233;
_parent.imageLoader._y = 200;
_parent.imageLoader._xscale = 95;
_parent.imageLoader._yscale = 100;
_parent.imageLoader._alpha = 80;
}

centerPosition = 300;
            speed = 1/10;

moveDetails = function(){
var distance = (_root._xmouse - centerPosition);
_x += (distance * speed);
if (_x > 0 ) _x = -600;
if (_x < -600) _x = -60;
}

this.onEnterFrame = moveDetails;
[/AS]

now when it exits the loop i=10. it searches for picture10.jpg which doesnt exist.

aurelius u have written in your code
_root.loadPicture(i);

Buttons unclickable even when called from mail.swf. I replace the root with “this” and voila buttons are now clickable. only problem is: always i=10 and it searches for picture10 which dont exist. (i=0 to 9)

shouldnt this be in the onenterframe function though? … it didnt matter because it didn’t work either. still searches for picture10. coz i=10.

Try changing the onPress to this:


this.mc["movies" + i].onPress = function() {
                loadPicture(i);
};

(or maybe [“movies” + i] needs to be [“doubleM” + i], whichever of these clips is on top of the other needs to have the “onPress” (because you can’t click on a button which is underneath another clip . . . you can only click on the highest/top clip)).

“this” probably refers to “scroll.swf”. Hence, adding a “this.onPress” is only going to be one action for the one clip. What you want the for loop to do is add an “onPress” function to each movieclip, so that the loop generates


this.mc.movies0.onPress = function() {
  loadPicture(0);
}

this.mc.movies1.onPress = function() {
  loadPicture(1);
}

this.mc.movies2.onPress = function() {
  loadPicture(2);
}

// etc.

(or this.mc.doubleM0.0/1/2/etc. if this is the clip that needs to be clicked . . . )
Let me know if that works.

i am starting from scratch. file attached. now if onPress or onRelease is supposed to change that instance from a movieclip to a button instance, why am i not able to click on it? i tried changing the level to zero but i cant still click on it.

if it has changed to a button instance, then i should be able to see the handcursor right?

Could you post the .fla so we can see the code?

i posted the zip file along with the image in the earlier post. in case u have missed it. :slight_smile:

i am also wondering if the following code will help preload the image before assigning the button instance:
[AS]
for (i =1;I<=9;i++) {
this.createEmptyMovieClip(“movies”+i,i)
loadMovie(“image.jpg”, “movies”+i);

loadKB = 0;
totalKB = this[“movies”+i].getBytesTotal;
while(loadKB < totalKB) {
loadKB = this[“movies”+i].getBytesLoaded;
}
this[“movies”+i].onKeyPress = some function

[/AS]

i think its a problem of assigning the button instance before the image loads. thats what even LIB has mentioned in one of his earlier posts.

I’ve attached a .fla that loads your image and then turns it into a button.

While I was making this, I realized what it was that’s been causing you problems. Silly me, I should have thought of this before, but it slipped my mind. The trick is this: you can’t turn images into buttons.

This is because in order for a button to work, it has to have some kind of vector-based content which the mouse can detect. I.e. the mouse has to be able to detect that it is over something in order to click on that something. An image is not vector based, so the mouse can’t really tell that it’s over the image. When you load an image into an empty clip, Flash still considers that clip an empty clip as far as mouse interactivity goes.

To counter this, you simply create an invisible block of color over the image and set that invisible block of color as the button. That’s what I did in the .fla.

On the other hand, you can edit the _x, _y, _xscale, _yscale, _alpha, etc. of the loaded image, but as we said earlier, this has to be done after the movie is loaded. I’ve put all the code that modifies the clip (changing it’s properties, creating an invisible overlay button, etc) inside one function called setMovieProperties(). That function is not called until the “swonking” function says the image is totally loaded (a “swonking” function is a function that checks for when something is loaded).

Unfortunately, movieClips don’t have an “onLoad” event handler that works like the “onLoad” handlers do for XML and LoadVars objects (wouldn’t it be nice if MovieClips did). So we have to check whether the bytes have completely loaded. This is an annoying process, but you’ll see how I did it with my “swonking” function (compare my code with the code you just posted above for ideas).

Also, I’ve used the setInterval() function to execute the swonking function over and over again. If you’re not familiar with setInterval(), check out it’s entry in the actionscript dictionary.

Okay, that should give you some ideas and tips for proceeding.

Yeah, the .fla I posted should answer most of your questions, I think. The big issue is creating an overlay clip that will surve as the button. One comment though, the code you posted above will only execute once. That is, the “while” statement that checks if the clip is loaded will only execute once for each of the 9 for-loop iterations. What you need to do is use setInterval or a frameloop to execute this “check-if-clip/image-is-loaded” over and over again until the clip/image is loaded. Otherwise, that’s exactly the right idea, it does need to load.

aurelius that is the most beautiful thing i have seen since the last two days. I wasn’t able to go thru the code so far. Boy it would taken me weeks to figure this one out on my own. thanks buddy.

to summarize: the basic gist of what you are trying to do is similar to actual loading of:

  1. movieClip and
  2. edit that movie clip and convert that instance into a button.
    (like we do when we are actually converting images to symbols and buttons to symbols).

i wonder though earlier when I used to run the “child” scroller.swf file from the main.swf file, how come the mouse pointer changed to hand cursor? i mean, if it did not recoganize the images as buttons in the child file, how does it do so when called from the main file? just wondering! and i was elated earlier that i had coded it. :trout:

anyways thanks again. now i am going back to taking your code apart and understanding the syntax.

cheers

Why it gave you a hand cursor and opened a yahoo.com in a _blank window is still a mystery to me too. Very strange. It’s too early for me, I think I would need my coffee before I tried to figure that one out. :slight_smile: Maybe lostinbeta can figure that out without coffee? :wink: