2-way switches in Flash? All done! Lockage please. (Full Version)

All Forums >> [Gaming Community] >> [Legends and Lore] >> Artists of Legend >> Art Academy



Message


jiggibidy -> 2-way switches in Flash? All done! Lockage please. (8/31/2008 13:03:28)

I am in in the process of making an Energy Sword in Flash CS3, and was wondering how I could incorporate a 2-way switch. So that on the first click, the sword appears, and on the second click, the blade retracts.

Thanks in advance.

~Peace Out,

~Jiggi.




biG frend -> RE: 2-way switches in Flash? (8/31/2008 13:34:01)

Use an if statement and a variable.

So in the mainframe put this

sword = 0; (work in AS2 plzkthx)

Then give the button this actionscript.

on (release) {
	if (_root.sword=0) {
		//put your gotoandstop command for your animation here then add this to the bottom
		_root.sword = _root.sword+1;
	}
	if (root.sword=1) {
		//put your gotoandstop command for your animation here then add this to the bottom
		_root.sword = _root.sword-1;
	}
}




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 14:03:51)

OK, I had a go, and this is my code, it said that it had some sort of error:

quote:

sword = 0;
on (release) {
if (_root.sword=0) {
//gotoandstop blade
_root.sword = _root.sword+1;
}
if (_root.sword=1) {
//gotoandstop blade
_root.sword = _root.sword-1;
}
}




Mo -> RE: 2-way switches in Flash? (8/31/2008 14:43:32)

Are you sure you are using AS2? It may be because you can't put AS into graphics and such anymore in Flash CS3




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 15:14:43)

yeah, I'm sure I'm using AS2, I thought it might have been because I didn't make the switch a button, but now, after turning it into a switch, I tried it again, but still to no avail, here is the screenshot of the error report:
[image]http://i267.photobucket.com/albums/ii293/jiggibidy/energybladeerrorreport1.png[/image]
Could you help get me on the right track please?




biG frend -> RE: 2-way switches in Flash? (8/31/2008 15:44:57)

Its because your not using correct syntax. Remove the "//" all the "//" is, is basically commentary to explain the code. You should replace it with _root.mcnamehere.gotoAndPlay(frame);




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 15:47:24)

ah, ok, thanks very much, i'll try it now and let you know how it goes.




biG frend -> RE: 2-way switches in Flash? (8/31/2008 15:53:15)

Oh also put the sword = 0; in the FRAME actions not the button.




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 16:06:04)

Ok, Flash seems to be heving a problem with the sword = 0;
It says "Statement must appear within on/onClipEvent handler"




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 17:06:06)

What do you mean by "put it in the frame actions", where is the "frame actions"?




biG frend -> RE: 2-way switches in Flash? (8/31/2008 17:11:13)

Right click the frame and hit actions.




Davosaur -> RE: 2-way switches in Flash? (8/31/2008 17:12:17)

//just goto the first frame on the timeline and put the actions there that code is called "actions" hence ActionsScript




The Illusive Man -> RE: 2-way switches in Flash? (8/31/2008 17:13:06)

jiggi

Click the frame in the timeline. Then open the actions panel. Define the sword variable there.

Also, instead of just sword=0. Type this in the frame

var sword:Number = 0;

That tells flash that it is definitely a number and not a string. Just refer to it as sword later though.




Also, biG's code is wrong. Try this edited version:




#IN FRAME ACTIONS!
var sword:Number = 0;

#In your button actions

on (release) {
if (_root.sword==0) {
//DO YOUR gotoAndStop(); ACTION HERE!  THIS IS NOT LITERAL!  YOU MUST KNOW HOW TO DO A GOTOANDSTOP
_root.sword = _root.sword+1;
}
if (_root.sword==1) {
//DO YOUR gotoAndStop(); ACTION HERE!  THIS IS NOT LITERAL!  YOU MUST KNOW HOW TO DO A GOTOANDSTOP
_root.sword = _root.sword-1;
}
}


Try that




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 17:30:24)

Well, I tried that, but to no avail, here is my code: I think it may be my gotoAndStop's
quote:

on (release) {
if (_root.sword==0) {
gotoAndStop(1)
_root.sword = _root.sword+1;
}
if (_root.sword==1) {
gotoAndStop(5)
_root.sword = _root.sword+1;
}
}




Davosaur -> RE: 2-way switches in Flash? (8/31/2008 17:31:50)

or if your really lazy and being cheap like me you can do this :

make one MC then inside tham MC you have 2 buttons both on different frames, make sure you have a stop acion though

on both frames :
stop();

on button 1:
on (release) {
swordblade.gotoAndPlay(
gotoAndStop(2);

}


on button 2
on (release) {
swordblade.gotoAndPlay(2)
gotoAndStop(2);
}

!comments! ya thats what i do though if your gonna add a button animation ist the same thing just with a tween[or FBF..]




jiggibidy -> RE: 2-way switches in Flash? (8/31/2008 18:33:20)

K, I have the variable set on the first frame, on the layer with the blade on it, and here is my code, which is set on the button:
quote:

on (release) {
if (_root.sword==0) {
gotoAndPlay(12)
_root.sword = _root.sword+1;
}
if (_root.sword = _root.sword==1) {
gotoAndPlay(24)
_root.sword = _root.sword-1;
}
}

Frame 12 and Frame 24 are the frames that the blade appearing and disappearing are set to.




ShadowSlash -> RE: 2-way switches in Flash? (8/31/2008 18:55:07)

I know next to nothing about ActionScript, so punch me if this is wrong...
but maybe you're supposed to add the semicolon on the end of the gotoAndStop() ?
as in-
    on (release) {
    if (_root.sword==0) {
    gotoAndStop(1);
    _root.sword = _root.sword+1;
    }
    if (_root.sword==1) {
    gotoAndStop(5);
    _root.sword = _root.sword+1;
    }
    }


I just copy/pasted then added the semicolons :P
just wondering, ignore this if you know its wrong


quote:

Well, I tried that, but to no avail, here is my code: I think it may be my gotoAndStop's

quote:

on (release) {
if (_root.sword==0) {
gotoAndStop(1)
_root.sword = _root.sword+1;
}
if (_root.sword==1) {
gotoAndStop(5)
_root.sword = _root.sword+1;
}
}


Also make sure you have the code in the right place.




The Illusive Man -> RE: 2-way switches in Flash? (9/1/2008 3:45:01)

You are right ShadowSlash. You do need semicolons. I thought I made that clear, but apparently not.

If you still can't get it, i'll make a sample fla I suppose.




jiggibidy -> RE: 2-way switches in Flash? (9/1/2008 7:41:53)

I tried adding semicolons, and it still didn't work.
I would very much appreciate it if you would make a sample .fla.
This is really starting ot annoy me.




The Illusive Man -> RE: 2-way switches in Flash? (9/1/2008 10:24:41)

http://www.mediafire.com/download.php?adbaaa8wqaa

The script is different to biG's, but works the same.

I didn't comment it, but you can probably figure out what it does

-Al




jiggibidy -> RE: 2-way switches in Flash? (9/1/2008 12:11:44)

Bah, I still can't get it to work!
How about I send you the .fla and you could rectify it for me?




The Illusive Man -> RE: 2-way switches in Flash? (9/1/2008 12:21:32)

Why not I suppose... Upload on mediafire and PM me the link




jiggibidy -> RE: 2-way switches in Flash? (9/1/2008 13:44:24)

All sorted now. Thanks Althorne, I owe you one.

~Peace Out,

~Jiggi.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition
0.125