-
Recently I encountered a problem which really stumped me on the game project on which I have been working for some time:
I have Movie clip on the stage with a movie clip nested within it and within that MC, among other things, is a button. The problem? The button flat out doesn't work. I used the exact same button symbol with the same actionscript on the main stage and it worked perfectly fine.
Is this some kind of rule that I didn't know about?
The reason behind this chaos is somewhat long and complex, but to attempt to simply explain it:
I have a MC that is a little scroll with "Shop Inventory" written on it, and when it is double clicked a menu of items availible slide down. The button I am attempting to create is an object on that menu which, when clicked, should purchase the item.
-
Are you sure the targeting in the button is correct?
-
Positive. I created another instance of the button symbol on the main stage and copy-pasted the actionscript and it worked exactly as it should... I just need it to work within the MC, because, as I said, it is part of a drop-down menu, so it needs to move with the rest of the menu.
EDIT: I have tried everything I can think of, including completely recreating the button from scratch multiple times...
[Edited by Neon Ninja on 04-13-2002 at 09:32 PM]
-
Thats not what I meen. If it works on the main stage and not in the movie clip there is a good chance the targeting is wrong. If you post the code I could take a look at it.
-
The code for the whole game is huge, because it is a full game, this is just a new component I am working on.
The button is simply incrementing a text field variable on the main stage and decrementing another. Here is the actionscript on it:
on (release) {
if (_root.gold>=40) {
_root.gold-=40;
_root.regs+=1;
}
}
It's fairly self explanitory what it's doing (or should be doing)- by clicking the button you are purchasing 1 reg for 40 gold in the game.
Oh, and btw, I essentially taught myself Actionscript and Flash, so my meathods probably aren't the cleanest but they work for me
-
Well it doesnt look like a prob with the targeting... and as long as 'gold' and 'regs' are on the main stage it should work. But sence it doesnt... I have no idea.
-
Aye, they are. *sigh*
Getting on my nerves, I'd like to know what's wrong and fix it so I can finish this update of the game and get it posted =P
-
You could be looking at one of the lost or heap reference / state phenomena (can't spell). Variables in the main timeline fail to recieve updates from movies clips events. You might try creating the variables in an object. IE
_________________________________________________
// Within the root timeline.
var gold; var reg;
// declare all the items.
{
// the declaration of inventory.
gold = {
bank : 0,
spend : new function(amount) {
if(amount > this.bank) {
return false;
} else {
this.bank -= amount; return true;
}
},
getPaid : new function(amount) { bank += amount; }
}
// objects like reg have cost and they can be bought and
// sold so we describe them as an object.
regs = {
inventory : 0,
cost : 40,
buy : new function() {
if(gold.spend(this.cost)) {
this.inventory++;
return "Regs purchased";
} else {
return "Ya can't afford that!";
}
}
}
//....
//other items below that could be in inventory.
}
--------------------------------------------------
// Button would call
on (release) {
_root.regs.buy();
}
---------------------------------------------------
Use this collaboration of objects and it should work. This
get's rid scope black holes. Let me know how it turns out.
-
Well, the problem is that the button doesn't work PERIOD I have discovered. For example, even a mouseover in the button will not work when it is nested within the MC.
-
President, save the New Zealand dollar foundation
are you sure the button instance has the behaviour "button"
check the instance panel,
you might have bumped something along the way changing it to "movieclip" or "graphic", in which case it wouldn't rollover or accept button events/actions
-
A button (or a nested MC with onMouse.. events) nested inside another MC that had onMouse/onRoll.. events on it will not work.
The containing MC will intercept all the mouse events and they will not reach the contained button or MC.
This sucks.
-
To get around that change the button's behaivor to "track as menu item" rather than "track as button"
-
Originally posted by etcettra
To get around that change the button's behaivor to "track as menu item" rather than "track as button"
Uhu - doesn't work.
The only way I've found is to write code to delegate the mouse events down to the contained MC's.
-
Well, thanks for the tip on why that doesn't work. I guess the only option I can think of is to break it up into 2 different MCs on the stage and have one with the ability to be moved/double clicked, and the other will be the pull down and just use a command to continously keep the X/Y coords the same.
-
Well, for those curious, that worked fine... though probably not the most efficiant way of getting it done, it worked.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|