Event Handler problems MC Button issues

[QUOTE=jillymo]Okay I need more help. I have gone this far with the same fla I was talking about before- Here is the as:

onClipEvent (load) {
_alpha = 0;
}
on (rollOver) {
_alpha = 100;
}
on (rollOut) {
_alpha = 0;
}
on (release) {
loadMovie(“question.swf”,0);
}

to be honest i never code on buttons but on the timeline. You have to use the enabled property so if you give it an instance name btn this might work

on (release) {
loadMovie(“question.swf”,0);
btn.enabled = false;
}

there may be a better way of doing this

Well I don’t have any way of doing it so your way sounds good to me. I will give it a try and see what happens. The reason I am coding on the button/mc is cause this is going to be a US map with the 50 states selectable. I thought it would be easier to keep the code on each state rather than targeting everything through the code. I may be wrong that it is a good way to do it, but that’s how I learn. :mu:

Thanks again Stringy

the only reason I can think of that it wouldnt work is because I think I will have to set the value to false once it has been clicked…and also I will have to figure out how it will remember that once a new swf has been loaded and it goes back to that original swf. But hey tomorrow is another day :z:

Actually, jillymo, if you store all the states’ instances into an array, you can make a loop that sets all the buttons to do the same thing. I think doing this is much more efficient and worth while, not to mention finger saving. You will have to code this on the timeline though.

Sounds good, but one thing that is going to be different about each state is that they will each load a different swf. It is going to be a quiz that has a question for each state then once they answer that question that state should no longer be accessable to them. Would that still work?

I am not very advanced in as capabilities. I am try hard though and would NEVER be able to it without all the help I have had from everyone in this forum…

:party:

Well in that case you would need another array to store the different quiz .swf. It’s a little complicated if you’ve never touched upon arrays before, but nothing you cant handle.

if you label all your buttons btn1,btn2,btn3 etc and all your swfs movie1,movie2,movie3 you can do this very easily from the timeline without any need for arrays.

Well can people give me thier opinions on what would be the most efficient way? arrays vs. AS on its own layer on the timeline?

The array thing I would really have to study up on :cubs:

Niether of them are very comlicated and you may find your self using both.
Heres a quick example which might help you get started
create a button(or mc),give it a linkage identifier of btn and delete from the stage. Type this on the first frame

myArray = ;
for (i=0; i<52; i++) {
myclip = attachMovie(“btn”, “btn”+i, i);
myclip._x = random(600);
myclip._y = random(400);
minorArray = ;
//this is quite a useful thing to do
_root[“btn”+i].ivar = i;
minorArray.push(_root[“btn”+i]);
minorArray.push("Question "+i);
minorArray.push(“Answer “+i);
minorArray.push(“movie”+i+”.swf”);
myArray.push(minorArray);
delete minorArray;
myclip.onPress = function() {
trace(myArray[this.ivar]);
this.enabled = false;
};
}

I realise you are not using attachMovie but this was just for quickness, to demonstrate how useful loops/arrays can be.

Well I have used attachMovie before so that is not too foreign to me, I just thought it may get too complicated for what I was attempting to do. I am currently reading through Senocular’s lesson on OOP hoping to get a better grasp on what I am working with.
I will give your example a try and I really appreciate the help :azn:

yeh, the attachMovie part is irrelevant really, just a way to get mc`s on the Stage quickly so you can test the rest of the stuff.

Wow. I can’t believe how much that seems to accomplish in such a small amount of steps. I feel like such an ActionScript baby :crying:

One of the first things I see though is that I want each mc or button I have to have a unique shape (all the states) Could I still use this set-up along with swap symbol or something? But I guess I can’t use swap symbol too well if my mc’s aren’t actually on the stage…

I think you would be better placing them manually on the Stage and painstakingly give them all instance names but you could still save yourself a lot of work.
eg/
//mcs labelled mystate0,mystate1 etc
swfs to load called movie0.swf,movie1.swf etc
createEmptyMovieClip(“container”, 5);
for (var i = 0; i<52; i++) {
this[“myState”+i].ivar = i;
this[“myState”+i].onPress = function() {
loadMovie(“movie”+this.ivar+“.swf”, “container”);
this.enabled = false;
};
}

hmm…well I will test this out and see what happens before I ask any more questions. I do thank you for all the info you have provided so far. I am pretty amazed that it seems to be so easy to do all these things with just the AS. If only I understood it all better…someday…

Stringy!!
Do you realize that you have done what would have probably taken me like 50 hours to do?? I am so impressed and I don’t know how I could thank you enough.

:bounce: :hugegrin: (-: :beam: :sen: :angel: :sure:

Im glad it helped. Keep on looking at the Senocular tutorials, and youll soon be helping me.

Stringy- I am trying to put this code you so graciously provided me into words so that I can completely understand why it makes what I needed done work. I understand the basic idea but anyway without more bable here is what I am getting out of it:

//mcs labelled mystate0,mystate1 etc
//swfs to load called movie0.swf,movie1.swf etc
[COLOR=Navy][SIZE=1]createEmptyMovieClip(“container”, 5);
[COLOR=DarkRed]for (var i = 0; i<52; i++) {
this[“myState”+i].ivar = i;[/COLOR]
this[“myState”+i].onPress = function() {
loadMovie(“movie”+this.ivar+".swf", “container”);
this.enabled = false;
};
}[/SIZE][/COLOR]

:book: An empty movie clip called container is created on level 5 of my main movie. Now I know what this stuff in the middle (in red)does, but it’s explaining the exactness of the code that gets me. There is a variable and if it is less than 52, than an increment is added…which allows each state to be pressed once, in turn calling the function which loads an swf into the container mc, and once a state has been pressed it is disable.

Anyway, I know this is what happens but know it is missing some explanation. If you could fill in the exact words/process for me I would be so happy.

I think actually you explained it better than i can.
we are looping throught the sequence 52 times(from i=0 to i=51 inclusive) and each time a value of 1 is added to i.On the first loop, i will be 0, so the next line gives us this[“myState”+0].ivar = 0;

this - refers to the timeline, so you may well be able to replace with _root but later if you decide to load the movie into another it will cause you problems.
[“myState”+0] just refers to the movieclip myState0
its as if “this” or (_root) is an array and flash knows to look in “this” for the stuff inside the square brackets which it is what it is looking for.
ivar is a property we have given each mc and in this case it has a value of 0.
you can call ivar whatever you want,it doesn`t matter.
like saying Object.property=value
So each mc has a property ivar but they are all unique values making them useful.
The next line gives us
this[“myState”+0].onPress = function() {
loadMovie(“movie”+this.ivar+“.swf”, “container”);
//in other words (movie0.swf,“container”)
this.enabled = false;
};

inside a callback function “this” refers to whatever is calling the function not to the timeline as you might expect. So this just means(on our first loop)
myState0.enabled = false;

Then it does the whole thing again with 1 etc.

Thanks AGAIN Stringy. It seems so easy once the code is written and explained. I just wonder when I will ever get to the point when I will be able to work through these things on my own and be able to write the script myself. I would have made this such a long process never realizing that it could all be addressed with one block of script rather than basically doing the same thing over and over for each mc. I just hope one of these days the lightbulb finally comes on…

:smiley:

We have all been there Jillymo but you are doing the right thing in trying to understand code rather than just copy it blindly. Once you have used it a couple of times you`ll wonder what all the fuss was about.

L I hope so!