Hi iam creating a simple flash game where you have to put objects in a certain bin eg metal things in a bin set as a movie clip called metal. So far user can select the items drag them to the right bin and when they release the mouse on the bin the items visible is set to 0 so it looks like it has gone in the bin. My problem now is that i want the user to be sent to a new scene once all the items have been successfully dragged and dropped over a bin and their visible is set to 0 but being a complete beginner i cant get this to work although i am guessing it should be simple enough to do. My code so far that works is this: cola.onPress = function() { startDrag(this, true); }; cola.onRelease = function() { stopDrag(); if (cola.hitTest(metal) == true) { setProperty(this, _x, 450.3); setProperty(this, _y, 340.3); setProperty("cola", _visible, "0"); } else { setProperty(this, _x, 40.5); setProperty(this, _y, 67.5); } }; food.onPress = function() { startDrag(this, true); }; food.onRelease = function() { stopDrag(); if (food.hitTest(metal) == true) { setProperty(this, _x, 450.3); setProperty(this, _y, 340.3); setProperty("food", _visible, "0"); } else { setProperty(this, _x, 40.5); setProperty(this, _y, 67.5); } }; spanner.onPress = function() { startDrag(this, true); }; spanner.onRelease = function() { stopDrag(); if (spanner.hitTest(metal) == true) { setProperty(this, _x, 450.3); setProperty(this, _y, 340.3); setProperty("spanner", _visible, "0"); } else { setProperty(this, _x, 40.5); setProperty(this, _y, 67.5); } }; rings.onPress = function() { startDrag(this, true); }; rings.onRelease = function() { stopDrag(); if (rings.hitTest(plastic) == true) { setProperty(this, _x, 100.3); setProperty(this, _y, 340.3); setProperty("rings", _visible, "0"); } else { setProperty(this, _x, 40.5); setProperty(this, _y, 67.5); } }; bottle.onPress = function() { startDrag(this, true); }; bottle.onRelease = function() { stopDrag(); if (bottle.hitTest(plastic) == true) { setProperty(this, _x, 100.3); setProperty(this, _y, 340.3); setProperty("bottle", _visible, "0"); } else { setProperty(this, _x, 40.5); setProperty(this, _y, 67.5); } }; I have tried adding things like: if (bottle and rings and spanner and cola and food.visible == 0) { gotoAndStop("Clean up done", 1); } But not getting any beguiners luck hope someone can help sorry for the long message.
hi, I tried to reply to this before but it got blocked... have a look at something like this: // setup an array to hold your objects testObjectArray = ["cola", "food", "spanner", "rings", "bottle"]; fCheckBinState = function () { // decalare a variable for the rubbishInBin rubbishInBin = 0; for (rubbish in testObjectArray) { if (testObjectArray[rubbish]._visible == false) { rubbishInBin++; } } if (rubbishInBin == testObjectArray.length) { // everything is right to go gotoAndPlay("CleanUp"); }else{ trace("we aren't all in the bin yet"); } }; // Use a single For...In loop to establish all the .startDrag() behaviours for(itemsToDrag in testObjectArray){ this[testObjectArray[itemsToDrag]].onPress = function(){ this.startDrag(); } } // this part can be done a number of ways but doing it individually for the moment might be easier to understand cola.onRelease = function() { // once inside this behaviour, we can refer to the movieClip as 'this' if (this.hitTest(metal) == true) { // unless you are using an old version, instead of setProperty, you can reference this way this._x = 450.3; this._y = 340.3; this._visible = false; // call the function fCheckBinState to see if all items are in the bin IF this item hitTest = true fCheckBinState(); } else { this._x = 40.5; this._y = 67.5; } stopDrag(); }; You will need to add in the other onRelease statements... remember to include the function call... One other thing, in the function call the gotoAndPlay("cleanUp") is a reference to a frameLabel that you will need to put in for this action. In your example you had gotoAndPlay("clean up done",1); ... one hint here... DON'T !!! Don't use scenes and sceneNames for navigation, it is buggy, use frames and frameLabels instead. hope that points you in the right direction cheers,
Thank you very much for your reply mandingo i have had to re cerate an account here cos something went wrong hence being called kingcarter2, anyway, I have implemented the code that you suggested thank you for putting it in a way i found easy to understand, the code now compiles but still won't move onto the frame now named "clenedup" even though the five items have been put in the bins :( and when i put the 5th and what should be the last item in the bin I get the output message trace "we aren't all in the bin yet" instead of moving on as I would like it to and the user is stuck on the current frame. I would be very great full of any help i could get with this again. current action script is now this: // setup an array to hold your objects testObjectArray = ["cola", "food", "spanner", "rings", "bottle"]; fCheckBinState = function () { // decalare a variable for the rubbishInBin rubbishInBin = 0; for (rubbish in testObjectArray) { if (testObjectArray[rubbish]._visible == false) { rubbishInBin++; } } if (rubbishInBin == testObjectArray.length) { // everything is right to go gotoAndPlay("cleanedup"); }else{ trace("we aren't all in the bin yet"); } }; // Use a single For...In loop to establish all the .startDrag() behaviours for(itemsToDrag in testObjectArray){ this[testObjectArray[itemsToDrag]].onPress = function(){ this.startDrag(); } } // this part can be done a number of ways but doing it individually for the moment might be easier to understand cola.onRelease = function() { // once inside this behaviour, we can refer to the movieClip as 'this' if (this.hitTest(metal) == true) { // unless you are using an old version, instead of setProperty, you can reference this way this._x = 450.3; this._y = 340.3; this._visible = false; // call the function fCheckBinState to see if all items are in the bin IF this item hitTest = true fCheckBinState(); } else { this._x = 40.5; this._y = 67.5; } stopDrag(); }; food.onRelease = function() { if (this.hitTest(metal) == true) { this._x = 450.3; this._y = 340.3; this._visible = false; fCheckBinState(); } else { this._x = 40.5; this._y = 67.5; } stopDrag(); }; spanner.onRelease = function() { if (this.hitTest(metal) == true) { this._x = 450.3; this._y = 340.3; this._visible = false; fCheckBinState(); } else { this._x = 40.5; this._y = 67.5; } stopDrag(); }; rings.onRelease = function() { if (this.hitTest(plastic) == true) { this._x = 100.3; this._y = 340.3; this._visible = false; fCheckBinState(); } else { this._x = 40.5; this._y = 67.5; } stopDrag(); }; bottle.onRelease = function() { if (this.hitTest(plastic) == true) { this._x = 100.3; this._y = 340.3; this._visible = false; fCheckBinState(); } else { this._x = 40.5; this._y = 67.5; } stopDrag(); };
Hi, Sorry long weekend here... I found the flaw in my code... sorry about that... the short version for the fix is as follows... fCheckBinState = function () { // decalare a variable for the rubbishInBin rubbishInBin = 0; for (rubbish in testObjectArray) { if ([b]this[testObjectArray[rubbish]][/b]._visible == false) { // I didn't make the correct reference here trace(testObjectArray[rubbish] + " is in the bin"); rubbishInBin++; } } if (rubbishInBin == testObjectArray.length) { // everything is right to go gotoAndPlay("cleanedup"); } else { trace("we aren't all in the bin yet"); } }; I have made a mockup and I will attach it for you... but I tested this and it all works. hope that helps... cheers,
Don't see what you're looking for? Try a search.
|