Help Make This Code Simple...
Code: if ((main_selection != mc_eps) && (main_selection != mc_games) && (main_selection != mc_contact) && (main_selection != mc_about))
Hi...is there any way of making this code simplier.The line in the code is really long...and I cant help but feel it is AS overkill...and that maybe there is a simplier way.??
Thanks
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 04-06-2007, 12:21 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Beginner (I Want To Make A Simple Button With Code)(very Basic)
I've had some success with AS3, but so far all the code I've written just runs once the program starts, and thats it. The code is attached to the first frame of the flash file.
I want to be able to take the code I've already made, and stick it into a button, so the code will run every time the button is pressed, without having to reload the whole program.
Basically all I want to do is make a button that runs the code:
trace('hi');
every time it is pressed.
Once I have that, I can figure out the rest by my self.
Please help.
Beginner (I Want To Make A Simple Button With Code)(very Basic)
I've had some success with AS3, but so far all the code I've written just runs once the program starts, and thats it. The code is attached to the first frame of the flash file.
I want to be able to take the code I've already made, and stick it into a button, so the code will run every time the button is pressed, without having to reload the whole program.
Basically all I want to do is make a button that runs the code:
trace('hi');
every time it is pressed.
Once I have that, I can figure out the rest by my self.
Please help.
Can You Help Me Fix Simple Javascript Code On Button Inside My Very Simple Component?
Flash MX 2004 (mac)
******************
Hi,
I have a custom component that consists of nothing more than two dynamic text feilds and a button. I want the button to open a popup window in the browser, and it does so using javascript (an extension i found).
I put the following function in the first (and only) frame of my actual component (and its also in the first frame of my entire movie, just in case):
callPopup = function() {
getURL(popup);
};
And then on the button in my component i have this:
on(press){
callPopup();
}
and then finally,there is a variable named 'popup' within my component (which would change in each instance) which is given a value in my test instance as :
"javascript:jspw3('../vwd_scripts/','popups/acroyoga.swf',',,0,Past%20Event,index,Past%20Event ,20,0,,0,450,550,0,0.001,0.001,,,1,0,,.0.0.');"
somewhere i am doing something wrong.. ..i am not sure if its the button code, or my link (variable 'popup') syntax. Or if its impossible to use javascript in this way.
I know my html page is set up correctly (correct info in the head of the page etc), since i am able to call the javascript from a regular html link (just for testings sake) which is on the same page as my swf.
Hmm..i hope i made some sense here.
I will be very gratefull for some help...i'm totally lost on this one...
thanks in advance
Cheska
Can You Help Me Fix Simple Javascript Code On Button Inside My Very Simple Component?
Flash MX 2004 (mac)
Hi,
I have a custom component that consists of nothing more than two dynamic text feilds and a button. I want the button to open a popup window in the browser, and it does so using javascript (an extension i found).
I put the following function in the first (and only) frame of my actual component (and its also in the first frame of my entire movie, just in case):
callPopup = function() {
getURL(popup);
};
And then on the button in my component i have this:
on(press){
callPopup();
}
and then finally,there is a variable named 'popup' within my component (which would change in each instance) which is given a value in my test instance as :
"javascript:jspw3('../vwd_scripts/','popups/acroyoga.swf',',,0,Past%20Event,index,Past%20Event ,20,0,,0,450,550,0,0.001,0.001,,,1,0,,.0.0.');"
somewhere i am doing something wrong.. ..i am not sure if its the button code, or my link (variable 'popup') syntax. Or if its impossible to use javascript in this way.
I know my html page is set up correctly (correct info in the head of the page etc), since i am able to call the javascript from a regular html link (just for testings sake) which is on the same page as my swf.
Hmm..i hope i made some sense here.
I will be very gratefull for some help...i'm totally lost on this one...
thanks in advance
Cheska
Simple, Simple Button Code ... *&^%£&
I have some buttons on my movie that are instances of SimpleButton. I have labelled one of them 'photo' - I want my buttons to register EventHandlers so that I can use them to load movies. I'd prefer to use 'frame code' if possible ...
For some reason (which I can't imagine), it seems that SimpleButton doesn't have an onClick/onRelease or equivalent event handler.
Do I have to write my own class just to get a button which has a proper EventHandler ? I know that can't be true. Who would provide a button class that doesn't have a mouse.click event handler in the standard libs ?
What do you do for this ? Help !
I wrote this code which seems to add an eventhandler and doesn't throw up any errors. Unfortunately it won't link to google either though ...
Code:
function photo_link(event) {
getURL("http://www.google.com","_blank");
}
photo.addEventListener(MouseEvent.CLICK, photo_link);
How Can I Make This Code Better
heres my code
Code:
if (c[0]+c[1]+c[3]+c[4] + .... + c[40]==0){
do something
}
as u can see i figured out how to make an array ....... basically the code sums all the elements in the array.
Why??
On my map engine i have 40 pieces each having its own hittest with the main character. If hittest ==true on mc0 then c[0]=1. Therefore when there is no hittest the sum of all the arrays elements are Zero.
thanks
Can You Make This Code Better?
Hi all,
I created an Infinite menu item and after reading through the forums I applied a few tweaks to get the follow behaviors:
a) only rolls when the mouse is over the MC
b) has a deadzone of about 200 pixels in the center for easy clicking
One problem i am having is that it will stop scrolling if I leave the swf above or below it, however sometimes it continues scrolling if I leave by the left or right edge.
I am also curious if this could be simplified.
Code:
onClipEvent (load) {
xcenterhigh = 442;
xcenterlow = 250;
speed = 1/20;
}
onClipEvent (enterFrame) {
if (this.hitTest(_root._xmouse, _root._ymouse, true)) {
if (_root._xmouse>xcenterhigh) {
var distance = _root._xmouse-xcenterhigh;
} else if (_root._xmouse<xcenterlow) {
var distance = _root._xmouse-xcenterlow;
} else if (_root._xmouse>xcenterlow) {
if (_root._xmouse<xcenterhigh) {
var distance = 0;
}
}
_x += (distance*speed);
if (_x>0) {
_x = -692;
}
if (_x<-692) {
_x = 0;
}
} }
Thanks,
Eric
How Can I Make This Code Better?
How can I make this code better:
ActionScript Code:
onClipEvent(load)
{
speed = 10;
speedx = speedy = speed;
targetx = this._x;
targety = this._y;
}
onClipEvent(enterFrame)
{
_x += (targetx - _x)/speedx;
_y += (targety - _y)/speedy;
}
I use the code to move object by changing targetx and targety with the click of a button.
The animation at the end seems to be 'jagged' - i.e. it kind of 'judders'.
How do I stop this?
Are there any better alternatives to the above?
AND... if possible, I'd like to do it in Flash 5. (But if there are better ways to do in MX, please let me know this as well.)
Thanks.
OM
Can You Make My Code More Efficient?
View the swf here: http://www.inflash.com/code.swf
The code tags for the board are italisizing everything and making it difficult to read, so you can view the code here:
http://www.inflash.com/code.txt
Tips, comments, etc?
[Edited by mbannonb on 08-02-2002 at 01:53 PM]
Make Code Loop
Is there a way to make actionscript code repeat itself in Flash 5?
Basically, I have a movieclip that I want to run some code, and then loop round and run it again, indefinatly. What is the trick?
----
Back in the old days of Basic you could do something like this:
10 print "hi"
20 goto 10
Is there a similar process to 'goto' in Flash 5 actionscript?
Make One Code For A Button.. Use For All
Is there a way I can make one button code do something on rollover, then have it use it for all the buttons that I set?
I have 16ish buttons, and I want to make them all do the same effect. They're all exactly the same size. I want them to do a rollover action, then a fade out action once I mouse-off.
Plus, it's all on an image I made in photoshop. So it's not flash, or vector, images. Not sure if that matters, but I thought I should say it.
Thanks guys, I really appreciate it.
Please Help Make Code 4 My Game, Please
hello, i need some big help with some action script codes.
My game is a warrior who you move by using the arrow keys, who can shoot a lightining bolt by pressing the space bar, if it hits the dragon, you get 10 points. after 70 hits, you win the game. The dragon moves across the background automatically and shoots its own fire ball at a time interval. Once this fireball hits you once you a transfered to a screen that tells you the game is over.
other information below, please read.
I need help in making a code that allows
my dragon to move across the screen , see dark red color above.
and when the dragon moves across the screen automatically, the fire ball fallows it until a certian time like 3 seconds and if it hits you, you are tranfered to a frame with game over text, frame 4, the fire ball keeps on firing at you always, and if it doesn't fir you, nothing happens. see lime color
*Everything is on its own layer
*dragon's instance name is dragon
*fireball's istance name is fireball
Thank you very much and it would be a joy to me if you can help me finish my game.
How To Make This Code Work In A Mc
I have this AS that works just fine when placed on the 1st frame of the main timeline, but I'd like to make it work when placed in a movie clip so that I can put multiple instances of MC's on 1 timeline that each use this code. Is this possible? What would I need to change in this AS do that?
Code:
function dragZoom(movieClip) {
_global.homeX = 314;
_global.homeY = 219;
_global.zoomIncrement = 10;
_global.zoomAmount = 200;
function zoomIn(movieClip) {
if(movieClip._yscale && movieClip._xscale < zoomAmount) {
movieClip._xscale = movieClip._xscale + zoomIncrement;
movieClip._yscale = movieClip._yscale + zoomIncrement;
} //end if statement
} //end zoomIn function
function zoomOut(movieClip) {
if(movieClip._yscale && movieClip._xscale > 100) {
movieClip._xscale = movieClip._xscale - zoomIncrement;
movieClip._yscale = movieClip._yscale - zoomIncrement;
} //end the if statement
} //end the zoomOut function
movieClip.onPress = function() {
this.startDrag();
movieClip.onEnterFrame = function() {
zoomIn(this);
} //end onEnterFrame
} //end onPress
movieClip.onRelease = function() {
this.stopDrag();
movieClip.onEnterFrame = function() {
zoomOut(this);
// Send the image back to the home on release
image._x = image._x - (image._x - homeX) / 5;
image._y = image._y - (image._y - homeY) / 5;
image2._x = image2._x - (image2._x - homeX) / 5;
image2._y = image2._y - (image2._y - homeY) / 5;
} //end on EnterFrame function
} //end onRelease function
} //end programm dragZoom
// Call the function dragZoom to activate!
dragZoom(image);
Is It Possible To Make That Code More Dynamic?
Hi
In that topic we were discussing about event handler. We are new to AS/Flash, but the result code seems so terrible... is not there any other way of getting the same thing but using a better code? We wouldn't like to have to write the name of every component we want to "dispatch".
Best Regards
Make Code Wait...
I am going to a function to build a big combo box, then selecting an item from it... but it seems that the select is trying to happen before the box is finished building... any ideas?
Thanks
Why Does This Code Make Something Slide?
Why does this code make something slide?
Code:
function pos4(evt:Event) {
var x1Goto:Number = 100;
var x1Pos:Number = t1up.x;
if (Math.abs(x4Goto - x4Pos)<1) {
t1up.x -= (t1up.x-x1Goto) / 6;
} else {
t1up.x -= (t1up.x-x1Goto) / 6;
}
}
I don't quite understand
Code:
if (Math.abs(x4Goto - x4Pos)<1)
t1up.x -= (t1up.x-x1Goto) / 6;
t1up.x is the x value of the movieclip
-= is used to minus a bit everytime the code is run or something
t1up.x-x1Goto minus where I want something to go from where it is
/6 is how fast or the size????
Please help me.
Regards,
Glen Charles Rowell
Make The Code Shorter ?
Hello everyone^^
It's my first post here, and my english is not very good, so I'm a bit stressed ^^. I hope I post in the good section.
Well. It's not really about a problem that I ask, it's just that I ask me some questions about how to mak some actionscripts shorter and more smart maybe.
I wonder if tere is a way to write shorter:
Code:
Mc.onRollOver = function() {
blahblahblah...}
Mc.onRollOut = function() {
nanananananana....}
titleMc.onPress = function() {
lalalalalalalala....}
btw: I discovered a few time ago,
Code:
that if(....){
blahblahblah...}
could be written a shorter way, but I can't find the syntax no more
Hope you can help me growing as a lil coder... ^^
~H~
How To Make Code From A String
i think u can do it via XML and the CustomFunctions methods in flash... but id rather do it all in flash if possible.
what i want to do is to treat a string as a line of code.
eg.
ActionScript Code:
actV="trace('Red')" someButton.onPress=function(){ actV.toCode() }
lol if only there was a toCode() method!!
can it be done? if so, how?
cheers,
Prophet.
Make Code More Efficient
Hello
On start up I make 6 objects "_visible = false;"
So when I click each of these 6 items corresponding buttons I do not want 6 lines of code every time turning 5 objects to "false" and one object to "true"
So is there a more effective method of coding than going
on (release) {
a= false;
b=false;
c=false;
d=false;
e=false;
f=true'
}
How To Make This Code Easier?
I have several buttons to load different txt files into an textfield. This is action for button1:
ActionScript Code:
loadText = new loadVars();loadText.load("textfile.txt");loadText.onLoad = function(OK) { if (OK) { myText.html = true; myText.htmlText = this.text1; }};
The problem is that i have like 30 buttons
Can anyone help me to set a function to make this easier?
Thanks in advance
Make The Code Shorter ?
Hello everyone^^
It's my first post here, and my english is not very good, so I'm a bit stressed ^^. I hope I post in the good section.
Well. It's not really about a problem that I ask, it's just that I ask me some questions about how to mak some actionscripts shorter and more smart maybe.
I wonder if tere is a way to write shorter:
Code:
Mc.onRollOver = function() {
blahblahblah...}
Mc.onRollOut = function() {
nanananananana....}
titleMc.onPress = function() {
lalalalalalalala....}
btw: I discovered a few time ago,
Code:
that if(....){
blahblahblah...}
could be written a shorter way, but I can't find the syntax no more
Hope you can help me growing as a lil coder... ^^
~H~
How To Make Code From A String
i think u can do it via XML and the CustomFunctions methods in flash... but id rather do it all in flash if possible.
what i want to do is to treat a string as a line of code.
eg.
ActionScript Code:
actV="trace('Red')" someButton.onPress=function(){ actV.toCode() }
lol if only there was a toCode() method!!
can it be done? if so, how?
cheers,
Prophet.
Make Code More Efficient
Hello
On start up I make 6 objects "_visible = false;"
So when I click each of these 6 items corresponding buttons I do not want 6 lines of code every time turning 5 objects to "false" and one object to "true"
So is there a more effective method of coding than going
on (release) {
a= false;
b=false;
c=false;
d=false;
e=false;
f=true'
}
Simple Code
What happened is that I have a button from another scene that one's click, it will go to this scene and once the player head starts playing I need to this code to run...
large.loadMovie = function() {
_root.createEmptyMovieClip("bg", 1);
loadMovie("topic1.swf", "_root.bg");
_root.bg._x = 0;
_root.bg._y = 0;
};
for people that are good that can see the error. Can you tell me what it is?
Thanks a lot guys,Niisa
Simple Code
Hello
I have what I think is a simple question.
I am trying to unload a movie when the mouse reaches a certain "X" position. Here is the code that I have tried
x_pos = _root._mouse;
if (x_pos <= 280) {
stop();
} else {
unloadMovieNum(1);
}
Thanks in advance
Looking For A Simple Code =]
hi, i need 2 codes both are basicly the same.
i need.....
when "Player" hits "Block" goto next scene.
When "box" hits "char" the box disapears and the sound "grr.wav" is played.
thankyou
Simple Bug In My Code
Hi,
This code is at the last frame in a movie and it loops until the value 'q' is equal to the value from a textfile. Unfortunately, it doesnt seem to ever meet the condition. Code :
var1 is entered by the user and it is therefore something like 1234.eng and q is the variable which is stepped up.
All I want it to do is detect it and then if it's equal value then goto frame 1 and if not, increase value of 'q' and then go to a start point half way through.
Code:
loadVariablesNum(var1+".eng",0);
if (q==frames) {
gotoAndPlay(1);
}
set(q, q++);
gotoAndPlay(65);
I know it's going to be a simple thing, but help would be greatly appreciated.
Cheers,
Sparky.
Please Help With Simple Code
ok, so i'm pretty new to actionscripting and i have a substantial amount of trouble with it. my problem is this. i've almost finished this site for a school organization. it is here
http://pages.emerson.edu/organizations/fps
however, in the "news" section of the page, i load an external text file called data.txt. for some reason, once the viewer opens the news section, the menu buttons stop working. i have no idea why the buttons don't work because they work in every other section of the site so i figured it must have something to do with the external text file. if anyone could help me out with this, i'd really appreciate it. i've attached the flash file. thanks.
Please Help With Simple Code
ok, so i'm pretty new to actionscripting and i have a substantial amount of trouble with it. my problem is this. i've almost finished this site for a school organization. it is here
http://pages.emerson.edu/organizations/fps
however, in the "news" section of the page, i load an external text file called data.txt. for some reason, once the viewer opens the news section, the menu buttons stop working. i have no idea why the buttons don't work because they work in every other section of the site so i figured it must have something to do with the external text file. if anyone could help me out with this, i'd really appreciate it. i've attached the flash file. thanks.
Help With Simple(?) Code?
Hello...I have my main movie with my nav on it and I am trying to get my button to load my swf "truthlies" into "empty" mc on main movie, but I want the truthlies.swf to go to and stop frame 6. I have tried code below but it is not working...am I close??? "Truthlies" loads fine, but I cant get it to go to frame 6.
on (release) {
loadMovie("truthlies.swf", "empty");
}
on (release) {
truthlies.swf.gotoAndPlay(6);
}
Thanks for any help here.
Need Simple Code
hey,
i really like this image effect on this website.
http://www.spezzo.com/main2.html
click on the "menus" link. When you mouse over a button, a picture flashes on the left hand side. How do i do that?
I am somewhat familar with A/S.
Thanks,
Baljinder
Little Code Help Please....simple
I'm having some problems with the following MC code
duplicateMovieClip("stick","trail1",1);
setProperty("trail1",alpha,50);
This is some code that I found which would make Onion Skin effect, but when I check for errors, it says alpha is not a property...
Anyone who has any idea what's going on, help would be much appreciated
thanks
-charley
Anybody Know How This Code? Simple I Think.....
i need a redirect code that will redirect visitors from one url to another url once they hit my page.
is this javascript or html? i have a regular html website that i want my visitors to be redirected to once they hit the old html website url....
thanx in advance
Simple Code
onClipEvent (load) {
title = "FOREIGN INVESTMENT";
}
on (release) {
getURL(title.toLowerCase()+".htm", "mainFrame");
}
on (rollOver) {
text.textColor = 0x008D84;
arrow.play();
}
on (rollOut) {
text.textColor = 0x712C7F;
arrow.gotoAndStop(1);
}
Need to be able to get FOREIGN INVESTMENT on 2 lines. Don't know too much about code and just pressing enter doesn't work. I have attached the flash file. I'm sorry if this is a stupid question but I don't have time to read the relevant tutorials as I'm in a big hurry to get this done. Thank you so much to the person who desides to help me.
Simple Code I Just Don't Know
I was wondering if someone could give me a hand.
I'm making a flash part for my site that show cases my portfolio, and i have loaded a swf over top of the _root
Now my problem is that when the new swf loads i can still click the buttons on _root
What is the code needed to make the buttons null only when the swf has been loaded?
Thank you for anyhelp
Simple Code?
Hey there, I'm using flash 5 and I've got this simple movie which switches the size of two boxes via actionscript:
on (release) {
// small to big
aa._x = 282.5;
aa._y = 263.9;
aa._xscale = 100;
aa._yscale = 100;
aa._width = 327.0;
aa._height = 189.9;
// big to small
bb._x = 135.5;
bb._y = 87.0;
bb._width = 155.0;
bb._height = 90.0;
}
You can see the example here: (click the red button)
http://www.liquid-visual.com/AB.swf
Now what I need to do is have it so when I click the button again it will send the boxes back to their original values. I've been playing around with some 'if' statements but nothing is working .. is there a simple way to do this?
This is a model for something bigger, what I REALLY want to do is control these values through if statements.
Example: when A and B are clicked, and equal X , box C will equal B on the next click. Get me? If not, don't worry, just need any option right now to switch the boxes back.
Thanks!
http://www.liquid-visual.com/AB.fla
(hopefully) Simple Code Help Please
Hello, I have a slide show and the following is the code I have to go forward to the next image...
on (release) {
_root.link = _root.link+1;
_root.play();
}
So what code do you think I might use to go go back to the last frame? I've tried
on (release) {
_root.link = _root.link-1;
_root.play();
}
But it doesn't seem to work....
Any ideas? Many thanks in advance!
Help W/ Very Simple Code
first of im completely new i hardly know any actionscript.
this code is for a game im making its in a movie clip called "ship":
onClipEvent(enterFrame) {
this._x = this._x + 2;
if (Key.isDown(Key.RIGHT)) {
this._x = this._x + 5;
}
if (Key.isDown(Key.LEFT)) {
disabled._x = disabled._x - 5;
}
if (Key.isDown(Key.DOWN)) {
this._y = this._y + 5;
}
if (Key.isDown(Key.UP)) {
this._y = this._y - 5;
}
if (_root.ship, hitTest(_root.block)) {
this._x = this._x - 2;
tellTarget(_root.ship.explosion)
play();
}
}
now I have another scene called "tryagain"
and once "_root.ship.explosion" is done playing i want the next scene to starts
any help would be great i just need help understanding like where i should put the code and what to put
Thank You!
Simple Code Help V_V
I'm creating a fighiting game and each character has his own stats, I'm having trouble implementing the different stats so can you guys help me out.
This is what I have:
I create a MC where I store all the characters (1 character per frame) each frame holds stop() and the character stats so it looks like this:
MC= player1thumb
code:
stop()
playerHP = 1000;
playerSP = 400;
Str = 20;
Def = 15;
(this is all in the movie clip "player1thumb")
on the scene screen I have the "player1thumb" movie clip and a dynamic box called "player1HP"
What code do I use to get the "playerHP = 1000;" to show up on the dynamic text box "player1HP"? (if I can get that then I can get the other stats just need an example )
so basically what code do I use to get variables from a MC to show up on Dynamic text in the main scene?
Can you guys help me out, or tell me if there is an easier way to have custom stats for each character?
Help With Simple Code
Ok, for some reason I can't do what it seems to be simple, this is the case, I have a button and I want that on release the button check if the frame of a movie clip IS NOT 2 execute an action, I think I am doing something wrong but I cant get it. this is the code:
Code:
on (release) { if(_root.sceneHolder_mc.contHolder_mc != (2)){
_root.sceneHolder_mc.gotoAndPlay("s1");
_root.sceneHolder_mc.contHolder_mc.gotoAndStop(2); } }
For Some reason when I press the button it goes to contHolder, frame 2, but when I press again it does not check and it execute again (not checking that if is telling it to dont do anything is is on frame 2)
please Help
[F8] Probably A Simple Bit Of Code, But...
Hey,
Here's what I need:
I have a movie clip which works as a button. There are 3 different frames; the Out, Over and Down states. And then there's the actual button layer hidden beneath these images.
I need the user to be able to roll over and out of the "button" and have it change between the 'over' and 'out' states accordingly. If the user clicks on the "button" it should change to the 'down' state.
And finally (this is what's getting me) if the user has clicked on the button, then when they rollOut the image needs to stay on the 'down' state image.
It would also be good if the user could un-select it by clicking on it again.
Here's what I've got:
I've labeled my frames and tried this action script on the hidden button. (var name = "hidden")
on (rollOver) {
gotoAndStop('over');
}
on (rollOut) {
if (hidden == __________) {
gotoAndStop('down');
} else{
gotoAndStop('out');
}
}
on(release) {
gotoAndStop('down');
}
I haven't really used "if else" statements before. I need to put something in the ______ area, but what? Or is there some other (read: easier) way I should be going about this?
Help With Simple Code
Code:
emailLink.addEventListener(MouseEvent.CLICK, goWhere)
function goWhere (evt) {
var url = "mailto:email@address.com"
navigateToURL(new URLRequest(url),);
}
This code doesn't work for email, does any one know why this is?
Thanks
Need A Simple Code
Hi!
Im totally new to actionscripting, and I really need help with making a simple code where someone can put their name in a box. The name + time and date of when the person wrote the name should be putted into a seperate text file.
I have almost no experience with actionscripting and nothing at all with php.
Could someone help me?
Thank you!
Help With Simple Code
In my Flash document I have aorrow keys on the stage (like the ones on your keyboard) with a text box under each one. The text boxes show a boolean (true or false value). It shows true if the corresponding key is pressed and false if it's not pressed (for example if you press the up arrow key on your keybaord the text under the up arrow key in the Flash file will change and show true instead of false, indicating that it's pressed. It will than change to false again once you release the button). However, I am having some trouble with this. When I press two or more keys down, the text boxes show true for the keys I pressed down, but if I release one key, the value then goes to false for all of the text files, not just the one I released. Please check out the attached .fla file (inside the .zip) and see if you can help me. Thanks in advance!
Here's the code I have in the file:
ActionScript Code:
var upKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
var leftKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
stage.addEventListener(Event.ENTER_FRAME, displayData);
function displayData(event:Event):void {
up.text = upKeyDown.toString();
down.text = downKeyDown.toString();
left.text = leftKeyDown.toString();
right.text = rightKeyDown.toString();
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
function keyPressed(event:KeyboardEvent):void
{
if (event.keyCode == 38){
upKeyDown = true;
}
if (event.keyCode == 37){
leftKeyDown = true;
}
if (event.keyCode == 39){
rightKeyDown = true;
}
if (event.keyCode == 40){
downKeyDown = true;
}
}
//trace(event.keyCode);
function keyReleased(event:KeyboardEvent):void
{
if (upKeyDown == true){
upKeyDown = false;
}
if (leftKeyDown == true){
leftKeyDown = false;
}
if (rightKeyDown == true){
rightKeyDown = false;
}
if (downKeyDown == true){
downKeyDown = false;
}
}
Need A Simple Code?
I need a simple code that I can put on an object when you click it, it goes to the next frame. I wanna make a simple game where you press and object to solve puzzles!
Anyone have a code that can do this!
|