FORUMS: list search recent posts

Animated Spot the difference issues: button's not behaving as scripted and no 'well done'?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Kate Burke
Animated Spot the difference issues: button's not behaving as scripted and no 'well done'?
on Sep 28, 2013 at 11:53:15 am

Hi
As you can tell for my very un-techincal description I am very new to coding. I have created an animated "spot the difference" game which is a scene "spotdifference" and is part of a master Christmas calendar "Scene 1". So each advent door (button) on Scene 1 will link to another scene that is either an animation or game.

What i would like to happen is for all spot_mc's to only appear when clicked on- at the moment they appear when rolled over.

Once all spot_mc's have been activated and there are 10 circles on the screen i then want this to go to a well done page (which i assume needs to be a different scene)
On this scene there would then be a return button (i have previously created with code) that would take the user back to "Scene 1" of the advent calender.


Here is the code pasted into "spotdifference":


{
var Spt1:Number = 0;
var Spt2:Number = 0;
var Spt3:Number = 0;
var Spt4:Number = 0;
var Spt5:Number = 0;
var Spt6:Number = 0;
var Spt7:Number = 0;
var Spt8:Number = 0;
var Spt9:Number = 0;
var Spt10:Number = 0;
var Comp2:Number = 0;


//circle1
{spot_mc.stop();
spot_mc.addEventListener(MouseEvent.CLICK, onBtnPress);

spot_mc.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut);

function onBtnPress(event:MouseEvent):void
{
spot_mc.gotoAndStop(1);
}


function onBtnOut(event:MouseEvent):void
{
if (spot_mc.currentFrame != 3)
{
spot_mc.gotoAndStop(3);
Spt1 = 5;
}
}

//circle2
spot_mc2.stop();
spot_mc2.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress2);

spot_mc2.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut2);

function onBtnPress2(event:MouseEvent):void
{
spot_mc2.gotoAndStop(3);
}


function onBtnOut2(event:MouseEvent):void
{
if (spot_mc2.currentFrame != 3)
{
spot_mc2.gotoAndStop(3);
Spt2 = 5;
}
}

//circle3
spot_mc3.stop();
spot_mc3.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress3);

spot_mc3.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut3);

function onBtnPress3(event:MouseEvent):void
{
spot_mc3.gotoAndStop(3);
}


function onBtnOut3(event:MouseEvent):void
{
if (spot_mc3.currentFrame != 3)
{
spot_mc3.gotoAndStop(3);
Spt3 = 5;
}
}

//circle4
spot_mc4.stop();
spot_mc4.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress4);

spot_mc4.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut4);

function onBtnPress4(event:MouseEvent):void
{
spot_mc4.gotoAndStop(3);
}


function onBtnOut4(event:MouseEvent):void
{
if (spot_mc4.currentFrame != 3)
{
spot_mc4.gotoAndStop(3);
Spt4 = 5;
}
}

//circle5
spot_mc5.stop();
spot_mc5.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress5);

spot_mc5.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut5);

function onBtnPress5(event:MouseEvent):void
{
spot_mc5.gotoAndStop(3);
}


function onBtnOut5(event:MouseEvent):void
{
if (spot_mc5.currentFrame != 3)
{
spot_mc5.gotoAndStop(3);
Spt5 = 5;
}
}


//circle6
spot_mc6.stop();
spot_mc6.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress6);

spot_mc6.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut6);

function onBtnPress6(event:MouseEvent):void
{
spot_mc6.gotoAndStop(3);
}


function onBtnOut6(event:MouseEvent):void
{
if (spot_mc6.currentFrame != 3)
{
spot_mc6.gotoAndStop(3);
Spt6 = 5;
}
}


//circle7
spot_mc7.stop();
spot_mc7.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress7);

spot_mc7.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut7);

function onBtnPress7(event:MouseEvent):void
{
spot_mc7.gotoAndStop(3);
}


function onBtnOut7(event:MouseEvent):void
{
if (spot_mc7.currentFrame != 3)
{
spot_mc7.gotoAndStop(3);
Spt7 = 5;
}
}


//circle8
spot_mc8.stop();
spot_mc8.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress8);

spot_mc8.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut8);

function onBtnPress8(event:MouseEvent):void
{
spot_mc8.gotoAndStop(3);
}


function onBtnOut8(event:MouseEvent):void
{
if (spot_mc8.currentFrame != 3)
{
spot_mc8.gotoAndStop(3);
Spt8 = 5;
}
}


//circle9
spot_mc9.stop();
spot_mc9.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress9);

spot_mc9.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut9);

function onBtnPress9(event:MouseEvent):void
{
spot_mc9.gotoAndStop(3);
}


function onBtnOut9(event:MouseEvent):void
{
if (spot_mc9.currentFrame != 3)
{
spot_mc9.gotoAndStop(3);
Spt9 = 5;
}
}


//circle10
spot_mc10.stop();
spot_mc10.addEventListener(MouseEvent.MOUSE_DOWN, onBtnPress10);

spot_mc10.addEventListener(MouseEvent.MOUSE_OUT, onBtnOut10);

function onBtnPress10(event:MouseEvent):void
{
spot_mc10.gotoAndStop(3);
}


function onBtnOut10(event:MouseEvent):void
{
if (spot_mc10.currentFrame != 3)
{
spot_mc10.gotoAndStop(3);
Spt10 = 5;
}
{
if (Spt1+Spt2+Spt3+Spt4+Spt5+Spt6+Spt7+Spt8+Spt9+Spt10 == 50)

{
stop();
welldone_spot.gotoAndStop(2);
Comp2 = 1;
}
}

}}
}



Any help would be greatly appreciated. Thanks :)


Return to posts index

demetri tashie
Re: Animated Spot the difference issues: button's not behaving as scripted and no 'well done'?
on Sep 28, 2013 at 5:54:37 pm

is this all part of a master function? if so, please include all the relevant code so we can see what drives the function.

in the meantime, a few things you can consider:

- don't think, or use, 'Scenes' in the classic sense that Flash allows. that is an older model held over from the old days of flash, and were the first break away from a purely linear flash 'movie'.

- keep all your code in one place, as you will run into far less issues and frustrating mistakes.

- consider using arrays, which can simplify functions and coding. here, you can make an array for all your movieclips ( spot_mc, spot_mc2 etc). then you can write just one function , which will cycle through the array and perform the action on all the clips. for instance, you can cycle through the array and stop all those movie clips from playing.

- changeing the EventListener from MOUSE_OUT to CLICK should change it from a rollover( actually a roll-out) to needing a click

- if movieclip 10's condition is met ( all the variables equal 50), then you can unload this module clip and load in the next desired clip ( a different way than using scenes. if you must use scenes, then you would direct the next 'scene' to play

- another movieclip in that module/scene, is scripted with an EventListener which listens for a click, and the function written directs it back to the original module/scene

here is some reworked code that does what I think you want to do, for 5 movieclips. It can maybe get you started to think about approaching the goals a little differently. this is of course just one way to approach it - there are others ways too. note that I made some important changes and adjustments to make it easier ( for me) to code). it takes you up the point of all five clips ( i made 5 - you willmkae 10) are clicked, and the function willdirect it to do something else.

there are lots of comments to help you understand what is going on. if you review it, and the linked SWF, and still have questions, let us know

// var names are built on the names of the related movieclips to make things easier
// values changed from Number to uint as this is smaller and better for memory and file size
var spot_mc0_var:uint = 0;
var spot_mc1_var:uint = 0;
var spot_mc2_var:uint = 0;
var spot_mc3_var:uint = 0;
var spot_mc4_var:uint = 0;

var Comp2:uint = 0;

// var created to help work with the names of the movieclips and the number variables
var strVar:String;

Comp2_txt.text = "Comp2 = 0";
welldone_spot.stop();

// this is the array of all the movieclips so we can work with them easily
var mcArray:Array = [spot_mc0,spot_mc1,spot_mc2,spot_mc3,spot_mc4];

// this for loop loops throught the array and stops all mcs, and assigns the same Event Listener to them all
for (var i:uint=0; i<5; i++)
{
mcArray[i].stop();
mcArray[i].addEventListener(MouseEvent.CLICK, onBtnPress);
}


// only one function is needed.
function onBtnPress(e:MouseEvent):void
{
e.target.gotoAndStop(3); // event target(the movieclip clicked) stops on frame 3
var eTargetname:String = e.target.name; // new var to capture the name of the clip clicked
strVar = eTargetname + "_var"; // this now becomes the variable
this[strVar] = 5; // changes the value of the correct variable to 5 (for your reasons)
//next line is for my purpose, and just shows on the stage the current total of the variable values
var_txt.text = String(spot_mc0_var + spot_mc1_var + spot_mc2_var + spot_mc3_var + spot_mc4_var) + "";
// if all the clips are clicked, the total of the variables should be 25. we can now do whatever we
// want. it directs the welldone_spot clip to got frame 3, and then you can navigate somewhere
// else, or whatever you want
if (spot_mc0_var + spot_mc1_var + spot_mc2_var + spot_mc3_var + spot_mc4_var == 25)
{
Comp2_txt.text = "Comp2 = 1";
welldone_spot.gotoAndStop(3);
// do something else, navigate somewhere else....
}
}


you can see a working example of this here
where the top 5 rectangles represent the 5 'spot_mc' movieclips, the large rectangle is 'welldone_spot', and 2 dynamic text boxes under them

i hope that helps you out


Return to posts index

Kate Burke
Re: Animated Spot the difference issues: button's not behaving as scripted and no 'well done'?
on Sep 29, 2013 at 7:58:46 pm

Hi Demetri
Thanks so much for taking the time to explain everything to me. I've made a new Action script file (just focusing on this game) and tried to implement the code you kindly pasted above.

In Scene 1 i have a single frame on frame one that is a movie clip with the instance name xmas_tree.
Inside this there are 14 layers, there is a layer for action script at top, followed by, welldone movie clip (that has an alpha channel of '0' on frame 1 so you can see animation underneath), each spot_mc are on a separate layer, and finally the left side movie clip of animated tree and right side clip (animated tree-with the 'spot the difference errors). I suspect now, the problem is more to do with how I've nested things or confusing which instance to put where... rather than the code- as it gives no errors. When I play the scene... half the spots/circles are missing and there if a flickering effect rather than enabling any interactivity, so sadly still not there yet :(

Can send the swf or flash file if easiest?


Thank you so much for you help!
Kate


Return to posts index


demetri tashie
Re: Animated Spot the difference issues: button's not behaving as scripted and no 'well done'?
on Sep 30, 2013 at 3:59:06 pm

the flickering effect is probably from short movieclip symbols that are playing and looping. this can happen when they are either nor directed to stop, and/or there are errors in the code/movie and it is not compiling correctly or fully. if you are not seeing error messages in the Output panel, then you will need to direct the problematic movie clips to stop.

do this in a dedicated actions layer on the first frame of the main movieclip(i.e. the actual 'movie' you are making). like this;
myProblematicMovieClip.stop();

and yes, your other problems certainly can be attributed to having your code placed incorrectly(in nested clips). i won't go over again - as there are tomes and endless forum discussions on - why we keep all of our code in one place, and in its simplest form, this would be on the first frame of the main movie.

i either don't understand, or can't see the question in the rest of your post. you can of course post your file, but i personally can't promise i can look at it right now, though of course others might look at it and chime in.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]