all groups > flash actionscript > august 2007 >
You're in the

flash actionscript

group:

PLEASE Help ASAP - deadline looming


PLEASE Help ASAP - deadline looming siney
8/28/2007 9:34:21 PM
flash actionscript:
Hi - I appreciate any specific help on this problem. I've developed a Flash
Drag & Drop game for kids to dress a character properly for winter snow sports
(skiing, snowboarding, xc & snowshoe) -- I've got everything working
beautifully except for the fact that I would like the give the user the choice
of a helmet OR a hat and still have either selection be considered correct. I
know I'm looking at a logical OR operator (or at least I believe I am) -- but
it is just NOT working. Can someone please please please take a look at my code
asap and let me know what you think the problem is? The helmet is comprised of
a mc with a nested button (instance name is 'boaderhelmet' - and the hat's
instance name is "boarderhat".....here's the whole code for all the items...
THANKS SO MUCH!


:confused;

var top1;
var top2;
var top3;
var pants1;
var pants2;
var feet1;
var feet2;
var glove1;
var glove2;
var helmet;
var hat;


wicktopmc.onPress = function(){this.startDrag();} // drag object you can put
this in your on(press) button code
layer2mc.onPress = function(){this.startDrag();} // drag object
boardjacketmc.onPress = function(){this.startDrag();} // drag object
wickpantsmc.onPress = function(){this.startDrag();}
boardpantsmc.onPress = function(){this.startDrag();}
boardsocksmc.onPress = function(){this.startDrag();}
boardbootsmc.onPress = function(){this.startDrag();}
glove1.onPress = function(){this.startDrag();}
glove2.onPress = function(){this.startDrag();}
helmetmc.onPress = function(){this.startDrag();}
hatmc.onPress = function(){this.startDrag();}
wicktopmcX = wicktopmc._x; // put circle back if dropped in wrong place
wicktopmcY = wicktopmc._y;
wicktopmc.onRelease = function(){
if (wicktopmc.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top1 = 'boardwickingtop'; // set top 1 variable to 'skithermalshirt'
}else{
stopDrag();
wicktopmc._x = wicktopmcX;
wicktopmc._y = wicktopmcY;
}
}
layer2mcX = layer2mc._x;
layer2mcY = layer2mc._y;
layer2mc.onRelease = function(){
if (layer2mc.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top2 = 'boardinsulating';
}else{
stopDrag();
layer2mc._x = layer2mcX;
layer2mc._y = layer2mcY;
}
}
boardjacketmcX = boardjacketmc._x;
boardjacketmcY = boardjacketmc._y;
boardjacketmc.onRelease = function(){
if (boardjacketmc.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top3 = 'boardjacket';
}else{
stopDrag();
boardjacketmc._x = boardjacketmcX;
boardjacketmc._y = boardjacketmcY;
}
}
wickpantsmcX = wickpantsmc._x;
wickpantsmcY = wickpantsmc._y;
wickpantsmc.onRelease = function(){
if (wickpantsmc.hitTest(pants_pos)){
stopDrag();
this._x=_root.pants_pos._x+(_root.pants_pos._width/2)-(this._width/2);
this._y=_root.pants_pos._y+(_root.pants_pos._height/2)-(this._height/2);
pants1 = 'wickpants';
}else{
stopDrag();
wickpantsmc._x = wickpantsmcX;
wickpantsmc._y = wickpantsmcY;
}
}

boardpantsmcX = boardpantsmc._x;
boardpantsmcY = boardpantsmc._y;
boardpantsmc.onRelease = function(){
if (boardpantsmc.hitTest(pants_pos)){
stopDrag();
this._x=_root.pants_pos._x+(_root.pants_pos._width/2)-(this._width/2);
this._y=_root.pants_pos._y+(_root.pants_pos._height/2)-(this._height/2);
pants2 = 'boardpants';
}else{
stopDrag();
boardpantsmc._x = boardpantsmcX;
boardpantsmc._y = boardpantsmcY;
}
}

boardsocksmcX = boardsocksmc._x;
boardsocksmcY = boardsocksmc._y;
boardsocksmc.onRelease = function(){
if (boardsocksmc.hitTest(feet_pos)){
stopDrag();
this._x=_root.feet_pos._x+(_root.feet_pos._width/2)-(this._width/2);
this._y=_root.feet_pos._y+(_root.feet_pos._height/2)-(this._height/2);
feet1 = 'boardersocks';
}else{
stopDrag();
boardsocksmc._x = boardsocksmcX;
boardsocksmc._y = boardsocksmcY;
}
}

boardbootsmcX = boardbootsmc._x;
boardbootsmcY = boardbootsmc._y;
boardbootsmc.onRelease = function(){
if (boardbootsmc.hitTest(feet_pos)){
stopDrag();
this._x=_root.feet_pos._x+(_root.feet_pos._width/2)-(this._width/2);
this._y=_root.feet_pos._y+(_root.feet_pos._height/2)-(this._height/2);
feet2 = 'boardboots';
}else{
stopDrag();
boardbootsmc._x = boardbootsmcX;
boardbootsmc._y = boardbootsmcY;
}
}

glove1X = glove1._x;
glove1Y = glove1._y;
glove1.onRelease = function(){
if (glove1.hitTest(hand_pos)){
stopDrag();
this._x=_root.hand_pos._x+(_root.hand_pos._width/2)-(this._width/2);
this._y=_root.hand_pos._y+(_root.hand_pos._height/2)-(this._height/2);
glove1 = 'boardglove1';
}else{
stopDrag();
glove1._x = glove1X;
glove1._y = glove1Y;
}
}

glove2X = glove2._x;
glove2Y = glove2._y;
glove2.onRelease = function(){
if (glove2.hitTest(hand_pos2)){
stopDrag();
this._x=_root.hand_pos2._x+(_root.hand_pos2._width/2)-(this._width/2);
this._y=_root.hand_pos2._y+(_root.hand_pos2._height/2)-(this._height/2);
glove2 = 'boarderglove2';
}else{
stopDrag();
glove2._x = glove2X;
glove2._y = glove2Y;
}
}

helmetmcX = helmetmc._x;
helmetmcY = helmetmc._y;
helmetmc.onRelease = function(){
if (helmetmc.hitTest(head_pos)){
stopDrag();
this._x=_root.head_pos._x+(_root.head_pos._width/2)-(this._width/2);
this._y=_root.head_pos._y+(_root.head_pos._height/2)-(this._height/2);
helmet = 'boarderhelmet';
}else{
stopDrag();
helmetmc._x = helmetmcX;
helmetmc._y = helmetmcY;
}
}

hatmcX = hatmc._x;
hatmcY = hatmc._y;
hatmc.onRelease = function(){
if (hatmc.hitTest(head_pos)){
stopDrag();
this._x=_root.head_pos._x+(_root.head_pos._width/2)-(this._width/2);
this._y=_root.head_pos._y+(_root.head_pos._height/2)-(this._height/2);
hat = 'boarderhat';
}else{
stopDrag();
hatmc._x = hatmcX;
hatmc._y = hatmcY;
}
}

checkClothes_btn.onRelease = function(){
trace('top 1: '+ top1 + ' top 2: ' + top2 + ' top 3: ' + top3 + ' pants1: ' +
pants1 + ' pants2: ' + pants2 + ' feet1: ' + feet1 + 'feet2: ' + feet2 +
'glove1: ' + glove1 + 'glove2: ' + glove2 + 'helmet: ' + helmet + hat);
if (top1 == 'boardwickingtop' && top2 == 'boardinsulating' && top3 ==
'boardjacket' && pants1 == 'wickpants' && pants2 == 'boardpants' && feet1 ==
Re: PLEASE Help ASAP - deadline looming .:}x-=V!P=-x{:.
8/28/2007 10:26:40 PM
if (top1 == 'boardwickingtop' && top2 == 'boardinsulating' && top3 ==
'boardjacket' && pants1 == 'wickpants' && pants2 == 'boardpants' && feet1 ==
'boardersocks' && feet2 == 'boardboots' && glove1 == 'boardglove1' && glove2 ==
'boarderglove2' && helmet == 'boarderhelmet' || helmet == 'boarderhat'){
.......
}
Re: PLEASE Help ASAP - deadline looming siney
8/28/2007 10:33:45 PM
thanks so much for your much needed help :) I have tried that -- in fact, my
latest effort is that I've replaced the var for hat and made it helmet - so
that it's only checking for helmet once....

hatmcX = hatmc._x;
hatmcY = hatmc._y;
hatmc.onRelease = function(){
if (hatmc.hitTest(head_pos)){
stopDrag();
this._x=_root.head_pos._x+(_root.head_pos._width/2)-(this._width/2);
this._y=_root.head_pos._y+(_root.head_pos._height/2)-(this._height/2);
helmet = 'boarderhat';
}else{
stopDrag();
hatmc._x = hatmcX;
hatmc._y = hatmcY;
}
}

However, with the code ending the way you've suggested and I've tried, it
seems like Flash is reading is as, if the character is dressed with the helmet,
correct; if the character is dressed with the hat, correct; OR if the character
just has the hat on, correct.....
Any thoughts on how to work that fix? Thanks again!
Re: PLEASE Help ASAP - deadline looming FlashForumName
8/28/2007 10:41:04 PM
If I am understanding you correctly, you want it to happen with all the other
variables true AND helmet OR hat which would be like this:



if ((top1 == 'boardwickingtop' && top2 == 'boardinsulating' && top3 ==
'boardjacket' && pants1 == 'wickpants' && pants2 == 'boardpants' && feet1 ==
'boardersocks' && feet2 == 'boardboots' && glove1 == 'boardglove1' && glove2 ==
'boarderglove2') && (helmet == 'boarderhelmet' || helmet == 'boarderhat'))
Re: PLEASE Help ASAP - deadline looming siney
8/28/2007 10:44:10 PM
That might be IT - I see you enclosed with ) and started again with ( to sep. out the helmet & hat condition....let me try that...

Re: PLEASE Help ASAP - deadline looming siney
8/28/2007 10:48:16 PM
Re: PLEASE Help ASAP - deadline looming FlashForumName
8/28/2007 10:52:21 PM
Re: PLEASE Help ASAP - deadline looming siney
8/28/2007 11:02:16 PM
One other quickie along those lines, suppose with one of the characters, I've
got both a hat & helmet; and sunglasses & goggles and wish to apply the same
logic that you can choose either/or and still be right?

I've got:

if (top1 == 'skithermalshirt' && top2 == 'fleece' && top3 == 'skijacket' &&
pants1 == 'basepants' && pants2 == 'skipants' && feet1 == 'skisocks' && feet2
== 'skiboots' && glove1 == 'skiglove2' && glove2 == 'skiglove1' && helmet ==
'helmet' && goggs == 'skigoggs'){


Re: PLEASE Help ASAP - deadline looming FlashForumName
8/28/2007 11:13:22 PM
You can add more checks to the if statement yes or you can do them inside a
nested if statement if you'd rather. You could have some something like this
for the goggles:


if ((top1 == 'boardwickingtop' && top2 == 'boardinsulating' && top3 ==
'boardjacket' && pants1 == 'wickpants' && pants2 == 'boardpants' && feet1 ==
'boardersocks' && feet2 == 'boardboots' && glove1 == 'boardglove1' && glove2 ==
'boarderglove2') && (helmet == 'boarderhelmet' || helmet == 'boarderhat') &&
(goggs=='skigoggs' || goggs=='sunglasses'))


or



if ((top1 == 'boardwickingtop' && top2 == 'boardinsulating' && top3 ==
'boardjacket' && pants1 == 'wickpants' && pants2 == 'boardpants' && feet1 ==
'boardersocks' && feet2 == 'boardboots' && glove1 == 'boardglove1' && glove2 ==
'boarderglove2') && (helmet == 'boarderhelmet' || helmet == 'boarderhat'))
{
if(goggs=='skigoggs' || goggs=='sunglasses')
{
...
}
}



etc
Re: PLEASE Help ASAP - deadline looming siney
8/28/2007 11:16:43 PM
Re: PLEASE Help ASAP - deadline looming siney
8/29/2007 5:32:28 PM
I'm back for more help if anyone has some ideas.....my problem with this drag &
drop quiz and here's the link:

http://www.northpoledesign.com/sia/newhowtodress/newhowtodress.htm

...is that I've checked with a variety of folks who have tried to dress the
characters properly & in-full; some are getting a Correct answer and some are
getting a NOPE - Try Again answer --- EVEN IF they've in fact dressed the
character properly. I've found that if you drag the jacket onto the character
first, then the base layer for example, you have trouble dropping the base
layer in place because the jacket is in the way, then when you are able to drop
it after a few clicks, it might not drop it exactly ON target, but yet, it
still snaps into position. I'm thinking this is what is causing the Incorrect -
try again - return.

If anyone has any thoughts or ideas as to how to make this 1000% bulletproof
so that it works for kids (& adults :) every time -- I wildly appreciate it! I
thought I had this thing nailed last night -- but alas, not the case
apparently. Thanks in advance!
Re: PLEASE Help ASAP - deadline looming FlashForumName
8/29/2007 7:30:37 PM
I took some of your code and in my testing it appears that, on occasion, the
release event of the dragable items does not fire. This is why it is not
lining up correctly even though the hittest should validate true, it never does
due to the release event not firing.
Re: PLEASE Help ASAP - deadline looming FlashForumName
8/29/2007 7:33:35 PM
If you are seeing the same result, it would lead me to believe that it has
something to do with the depth of the items causing the events to not trigger
at times. That's my best guess at this point, anyway.
Re: PLEASE Help ASAP - deadline looming siney
8/29/2007 7:35:47 PM
That sure seems to make sense and would contribute to the inconsistency that
folks are experiencing. What in the world is the solution to making sure the
release event releases and snaps to the intended drop target....and not to just
a portion of the drop target??
I even tried locking the items in place after you drop them. So if you drop
the jacket on first, then go back and try to drop the base layer, it still
won't let me do it easily. I've got to click around and ultimately it will, but
again, it might not be snapping 100% into the right spot somehow....
Re: PLEASE Help ASAP - deadline looming siney
8/29/2007 7:40:56 PM
For the depths of the items, I've actually got that set up with the items on
different layers; obviously with the base layers on the bottom and Layer 2 on
the next higher layer, etc. Any thoughts on other ways to set it up so they're
all on the same layer and get positioned & layered thru actionscript?
Re: PLEASE Help ASAP - deadline looming siney
8/29/2007 7:56:38 PM
I just took another look at the onRelease event and see that the hit test/drop
target shows that it's on the _root level; however, while that's true, so are
the items. I removed the _root reference on the first baseshirt and left it on
the next item so you can see what I mean....I haven't tried this across the
board, but it does work when I dress the character with just the baseshirt not
referencing the _root level....Do you think that would solve my primary issues
with the onRelease events? Thanks again!

baseshirtX = baseshirt._x; // put circle back if dropped in wrong place
baseshirtY = baseshirt._y;
baseshirt.onRelease = function(){
if (baseshirt.hitTest(shirt_pos)){
stopDrag();
this._x= shirt_pos._x+(shirt_pos._width/2)-(this._width/2);
this._y= shirt_pos._y+(shirt_pos._height/2)-(this._height/2);
top1 = 'skithermalshirt'; // set top 1 variable to 'skithermalshirt'
}else{
stopDrag();
baseshirt._x = baseshirtX;
baseshirt._y = baseshirtY;
}
}
fleecemcX = fleecemc._x;
fleecemcY = fleecemc._y;
fleecemc.onRelease = function(){
if (fleecemc.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top2 = 'fleece';
}else{
stopDrag();
fleecemc._x = fleecemcX;
fleecemc._y = fleecemcY;
}
}
Re: PLEASE Help ASAP - deadline looming FlashForumName
8/29/2007 8:03:03 PM
You can try this, it appears to be working in my testing. You'll have to
change the variable names to fit your objects(I just use mc_1, mc_2, etc) and
be sure to apply it to each event but it appears to be working on my end. Just
be sure to add the depth changes to each onPress and onRelease. You can give
it a shot and see if it fixes it or not. You can probably get by with just one
prevDepth variable but I used one for each for simplicity in my testing. You
can work that out however you want if this method fixes your problem.



var top1;
var top2;
var top3;
var prevDepth1;
var prevDepth2;
var prevDepth3;
mc_1.onPress = function()
{
prevDepth1 = this.getDepth();
this.swapDepths(_root.getNextHighestDepth());
this.startDrag();
} // drag object you can put this in your on(press) button code
mc_2.onPress = function()
{
prevDepth2 = this.getDepth();
this.swapDepths(_root.getNextHighestDepth());
this.startDrag();
} // drag object
mc_3.onPress = function()
{
prevDepth3 = this.getDepth();
this.swapDepths(_root.getNextHighestDepth());
this.startDrag();
} // drag object

mc_1.onRelease = function(){
this.swapDepths(prevDepth1);
if (mc_1.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top1 = 'boardwickingtop'; // set top 1 variable to 'skithermalshirt'
}else{
stopDrag();
mc_1._x = wicktopmcX;
mc_1._y = wicktopmcY;
}
}
layer2mcX = mc_2._x;
layer2mcY = mc_2._y;
mc_2.onRelease = function(){
this.swapDepths(prevDepth2);
if (mc_2.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top2 = 'boardinsulating';
}else{
stopDrag();
mc_2._x = layer2mcX;
mc_2._y = layer2mcY;
}
}
boardjacketmcX = mc_3._x;
boardjacketmcY = mc_3._y;
mc_3.onRelease = function(){
this.swapDepths(prevDepth3);
if (mc_3.hitTest(shirt_pos)){
stopDrag();
this._x=_root.shirt_pos._x+(_root.shirt_pos._width/2)-(this._width/2);
this._y=_root.shirt_pos._y+(_root.shirt_pos._height/2)-(this._height/2);
top3 = 'boardjacket';
}else{
stopDrag();
mc_3._x = boardjacketmcX;
mc_3._y = boardjacketmcY;
}
}
Re: PLEASE Help ASAP - deadline looming siney
8/29/2007 8:14:46 PM
wow - I appreciate that! I'll need to give that a shot....

I did a test on the skier file without the _root reference to see if that
would help and I'm returning a correct answer every time....any chance you
would take a sec and try and see if it works on your end? Here's the link:

http://www.northpoledesign.com/sia/newhowtodress/skierdresstest.htm

Thanks again! If it does work - I think this would be a quicker fix; but
otherwise, I'll try your solution.
Re: PLEASE Help ASAP - deadline looming FlashForumName
8/29/2007 8:23:19 PM
Re: PLEASE Help ASAP - deadline looming siney
8/29/2007 9:31:35 PM
with regards to the depths solution --- would I need to bring all the items of clothes onto one layer?
AddThis Social Bookmark Button