ActionScript 2.0 :: Holding Space, Increase Variable?
Nov 20, 2005
right now, my code looks like this:
Code:
onClipEvent(load){
speedy = 1.1;
gravity = 9.82;
[Code].....
What I want is that the flash should wait until I've finished pressing space, and the longer I hold in space, the bigger the variable speedx is. I can hold it in right now, but the ball will fall before I've released space. I'm really new to this so please be nice
EDIT: the flash is a ball that "throws", and the code is on the ball, which is a movie clip.
View 2 Replies
Similar Posts:
Dec 28, 2010
I am making my first game and it's my first time using actionscript. I am making a sniper game themed with the L96A1 sniper rifle from COD: Black Ops and the map nuketown. I'm in cs5 with ac3 and on my stage I have two movie clips that I'm working with. I'm not really sure if they're supposed to be movie clips though. Anyways, one is the gun, and the other is the zoomed in scope overlay thingy.
For now, I'm trying get the zooming in to work. I haven't done anything else though except collect graphics for enemies, the landscape, the gun, and the scope. I want to make it so that you zoom in and out by holding and letting go of the space bar. Also,I want to make it so that when you are not zoomed in, the gun moves horizontally at the bottom of the screen (aligned vertically with the cursor). And when you are zoomed in, the scope crosshair is the cursor.So my idea was to set the gun as the cursor and make it only move horizontally at the bottom of the stage and then make an event listener that listens to when the spacebar is pressed and when it is, disables the gun as the cursor (and makes it transparent to get it off the screen) and makes the scope the cursor [was transparent, now opaque and unrestricted(vertical movement also)].
I got as far as making the gun move horizontally at the bottom with the cursor. I cant get the event listener working because I don't really know how to go about changing the opacity of each movie clip and how to switch cursors. So I am asking how do I change the opacity and switch the cursors when the spacebar is held and then reverse those changes when the spacebar is released? Here's my code on an "actions" layer [I haven't done any animations yet, so everything is on frame 1. Also, I used a couple preset code snippets since I have no previous experience with actionscript (I can understand most of it though)]:
Code:
import flash.events.KeyboardEvent;
// make gun cursor
stage.addChild(gun);[code]..........
Here's a link to a zip archive with all the files used so far (I hope this google docs link works): link
View 2 Replies
Oct 26, 2011
I just added columnWidthRatio: 1; to my mx|ColumnChart to fatten up my columns a little. But now, there's no space between the X axis and columns, and between the columns themselves, so how do I increase this space?
View 1 Replies
Feb 17, 2009
I have a var defined and that is colour var colour = 0; and I want to increase var everytime you press space so I have an invisible button with this code in it
on (keyPress "<Space>") {
colour+1;
}
This is so that I can advance in a movieclip. I have the code for that here:
onEnterFrame; {
if (colour == 1) {
head.gotoAndStop(1);
}
[Code].....
View 5 Replies
Sep 21, 2006
I have a line of 12 horizontal placed buttons. I want whatever button is rolled over to get larger (no problem), but I need the other buttons to slide over to allow for the new size that the larger one would bring. I have no idea what type of code I should be looking for here.
View 1 Replies
Jan 26, 2011
I have an overlay that I pull up in response to a button click. This overlay is dynamically populated by a TextField, a MovieClip, and a Bitmap. I used to add them to the overlay with addChild() and induce a index out of bounds error to make them go away (I was in a hurry and I don't think I'm using removeChild() right). Well, I decided to do it better and dynamically change the object inside the holding variable. However... the Bitmap is gone. It won't appear. The overlay puller function takes a data-holding class I made and the picture is a BitmapData object.
I can't use the line new Bitmap(picture) because it doesn't work; that makes nothing appear. So, I guess my question is can I store a line of text in a variable and then use that variable as code? Like... Could I have something like this and get an image as an output? I imagine it could be done with XML, but is there another way? I tried storing the constructor in a variable and calling it with object.constructor, but I don't know if I was using it right and it didn't work.
[Code]...
View 2 Replies
Oct 19, 2009
I have this code, which should work fine, but it doesn't.
Unit1_Mobs_Destroyed += 1;
Text="Unit 1 destroyed "+Unit1_Mobs_Destroyed+" Mobs!" It should set Unit1_Mobs_Destroyed to current value + 1 If Unit1_Mobs_Destroyed is 5 at the start, it should be this: Unit 1 destroyed 6 Mobs But that doesn't happen instead I get this: Unit 1 destroyed 5 1 Mobs
View 2 Replies
Jan 1, 2011
i have a variable that i want to increase when you click somthing. the code im using is this but its not working
on (press){
w/e++;
this.startDrag;
}
i may have written the start drag wwrong but thats not the problem the variable wont increase. How can i do that? if what im doing isnt possible with as2, the reason im doing this is because i want my "game" to start after you get ready, so people arent caught off guard from starting right away and having a falling object not be caught.
View 7 Replies
Jun 29, 2010
I want to use two buttons, one for increase and the other for decrease, to change the numeric value of a variable. I will use this variable to call a line width in some lineStyle code that I have. Basically, the user will be able to use the buttons to change the width of the line they are drawing in real time. I have attached the fla with the beginnings of this section.
How do I get the buttons to affect my variable?
View 9 Replies
May 23, 2009
I am using the attachMovie script in as2 and I want to use a counter variable to increase the depth each time so it doesn't replace the last one. Every tutorial i've seen for attachMovie mentions this but I can't find any information on how.
Also is it possible to use a different counter variable to change to y position of the attached movieclip, so that it adds another beneath the last every time.
View 2 Replies
Feb 22, 2008
I am wondering if anyone has experience this problem before:
[Code]...
I was experiencing some other "strange" behavior so I'm wondering if my code is getting too long. Maybe I'm running into some kind of limit. Has this happened to anyone else? Anyone know of some fixes? The loop is in a _global function, could that be causing a problem? other than that, the code is on line 4420 of the actionscript coding interface.
View 1 Replies
Aug 19, 2011
How can I increase the _height property of a window without increase the height of the title and the bar at the top of the window ?
I want only to increase the part of the window where I put textFields and buttons.
View 6 Replies
Mar 28, 2011
scripting for holding a button down and having the action take place once.So thing is, I have code for pressing a button (which is the up arrow button)This was suppose to show the animation for someone shooting constantly until released:
if (Key.isDown(Key.UP)){ fox.gotoAndPlay(16); deploy.gotoAndPlay(2); trace("Pressed."); }
Unfortunetly the results are:Holding down the up key places out "Pressed." constantly instead of once.fox.gotoAndPlay(16) stays on 16 rather progressing the animation (to which should come back to 16 at a repeated process)deploy.gotoAndPlay(2) plays a sound but before: the sound played constanlty rather once) recently: sound never playsI also need code that prevents the player from moving when holding down the up arrow key.So in total, I want the player to be able to hold the up key, and everything executed is played once until pressed agan after release.I heard about adding listeners:
var myListener:Object = new Object(); myListener.onKeyDown = function() { KEY = Key.getCode(); if (!this[KEY]) { trace("You pressed "+KEY); } this[KEY] = true; }; myListener.onKeyUp = function() { KEY = Key.getCode(); trace("You released a key."+KEY); this[KEY] = false; }; Key.addListener(myListener);
but I can't understand this technobabble and everytime I try to work it, it only puts error outputs.
View 7 Replies
Jun 23, 2009
I am getting the session generated in Flex Application in a hidden text field, but when i refresh the page it gets back me to login page...
How can i hold the session of the page until the browser is not closed...
I am getting the session value from PHP.
View 2 Replies
Jan 15, 2010
How can I differentiate between these two actions in AS3? I'm working on a side-scroller,and I want to require the "attack" button to be pressed for each successive attackCurrently you can continuously attack by holding down the attack key. I'm using a standard event listener, i.e.
ActionScript Code:
private function keyDownFunc(event:KeyboardEvent)
{
[code]....
View 1 Replies
May 22, 2010
I have a mc which is a square. I want to make a grid with it. Everybody knows how a grid looks like. Heres the main issue: I want to have a full control over each single element of the grid. I want to put them all in a 2d array, so I can access them by giving a row and a column number, e.g, so as to remove a specific mc, Id write: container.removeChild[_myArray[i][j], where i and j stand for the row and the column.This is how my current method for creating the grid look like:
ActionScript Code:
private function drawGrid():void
{
var startX:uint = 0;
[code]...
It does draw a grid, but I dont have a power over it. And even if I do, I cant see any way of accessing a specific box.
View 3 Replies
Feb 1, 2010
I've created a textfield which I want to hold the time that is left of a flv being played. I also created a timer which will see to it that it gets updated.
Here is the code:
"import flash.utils.Timer;
import flash.events.TimerEvent;
var myTimer:Timer = new Timer(1000);
myTimer.addEventListener(TimerEvent.TIMER,updateCo untdown);
[Code]...
However, when i try to compile i get this error message: "1067: Implicit coercion of a value of type Number to an unrelated type String.
View 1 Replies
Apr 9, 2009
I have separated the background info on the "WHY", from the "WHAT" so that people can give me feedback on my question directly, but if they require more information, they can read my background info to understand the purpose of what I am doing.
======================================================
Background Info (the WHY):
======================================================
I am working with an actionscript structure as follows:On a specific frame exists a controlling function or "node". It contains a user defined array of "branches" or sub functions. These sub functions(branches) are of a user-defined class which can hold other code. Other programmers will be using this structure. When they work with it, they will be dynamiclly adding new "Branches" which the node will then run in whatever way they specify. I am coding the node, and creating the different execution options that the other programmers will be able to use.
One of these types of executions is for the node to LOOP through the branches (however many there may be) waiting for either a key press or a mouse click. On either input it should exit the node and continue on to the rest of the frame, and then the rest of the program.
My original structure is based on user defined Event Listeners and Dispatchers. Upon Entering the node I begin by defining:
addEventListener("BranchComplete",nextBranch); addEventListener("RepeatDone",runComplete);
runComplete executes when the node has finished, nextBranch is fired after each branch has successfully finished.
I originally fired off:
dispatchEvent(new Event("BranchComplete"));
as the last line of the Branch executing function. The problem with this was, the function "nextBranch" does not return until all that it has called/triggered has finished. "nextBranch" ends up being called recursively by the EventListener. This causes a stack overflow.
I then changed the code, by moving the 'dispatchEvent' command into the same function that added the EventListeners. This ensures the function "nextBranch" has finished and returned before the EventListener triggers it again. This prevents the recursion and the stack overflow, but creates a new problem: The 'DispatchEvent' only occurs once, as after the second time through the branch, it returns and continues on the line after the dispatch.
In order to get around this, i placed the dispatchEvent inside a do...While loop, that tracks a variable that is only set to false when the user gives Mouse or Keyboard input. Voila, problem solved, code loops forever while calling "nextBranch" and triggering "BranchComplete" events as they complete. The only problem is, user input doesnt seem to be caught, due to the infinitely repeating while loop.
To test that it does in fact work correctly, i set the While Condition to automatically turn false after 1000 iterations. This works perfectly, and exits after 1000 branches have executed, all triggered by the Dispatched events. So, I want it to loop through my Branches until Key press or Mouse click. It appears that during a while loop, Keyboard and Mouse Listeners will not trigger. Is this true, and what is the best solution for holding in a loop while waiting for an event listener to trigger?
View 5 Replies
Jul 31, 2011
I want to create flex/actionscript directory view for my files with php/mysql. I have some ideas that I want to share:
1)I am thinking of creating table (in mysql) "files" and another table "folders", when user loges in i will require all data from "files" and "folders" where Username = 'something'. But the problem is, I will create a lot of entries inside of tables. For example if I will have 100 users, and each user could create 100 entries (files or folders) it means that i will get 10000 entries inside table.
2)My second idea, and I think more safe way of doing it is creating table "users" where will be set id, username, password, ... , files, folders. In files (text format entry) will be listed information about files, and they will be dividend by "*" symbol like this:
id*file name*size(in kbytes)*path*status
example:
15*test.exe*150*/root/*private
16*test2.exe*200*/root/folder1/*public
[Code]....
Now here is only 3 file info but there can be more than 1000.
View 2 Replies
Nov 3, 2009
Having a bunch of dynamically-created MC's, what is the best way to store custom variables for each MC?Do I just make a hidden textfield inside each MC to hold the data?For example I have MC's called:-Apple1-Apple2-Apple3-etc...And inside each MC I have a variable appleEaten = X.And eventually I could use the data in an IF statement like:
View 4 Replies
Jan 24, 2006
I'm working on a project where I have Multiple instances with the same actions.
Instead of typing out
btn1._visible = false;
btn2._visible = false;
btn3._visible = false;
btn4._visible = false;
Could I store these instances in an array so that I could minimize my code to something like:
btnArray._visible = false;
I've tried to do this but it seems to read the instances as strings instead.
View 11 Replies
Apr 26, 2006
I'm working on a ACAD flash system, and one of the functions is to draw lines. Now I'd like to be able to draw vertical/horizontal lines by holding a key down (i.e. Shift). But I'm finding that the system is detecting me releasing the mouse (I'm not) while I hold another key.
Attached is a .fla file where you can click and drag a box.
Don't worry about posting "oh you should use startDrag()" and whatnot. The architecture of the actual application makes such things not feasible. This is just a test .fla.
The code is here:
ActionScript Code:
on (press) {
this.onMouseMove = function() {
trace('Mouse is moving');
[Code]....
So yeah, as you run it and drag the object around, you see a lot of "Mouse is moving", but if you press and hold any key, you'll also notice the "Mouse released" as well.
View 3 Replies
Jun 22, 2010
Having a bunch of dynamically-created MC's, what is the best way to store custom variables for each MC? Do I just make a hidden textfield inside each MC to hold the data? For example I have MC's called:
[Code]...
And inside each MC I have a variable appleEaten = X. And eventually I could use the data in an IF statement like: if appleY.appleEaten == X then do something. What is the best method, or generally common way of doing this? Maybe I'm already doing it,
View 2 Replies
Oct 19, 2010
I need to have the user click on a button, and until another button is clicked, keep that button on the "Down" state.
View 2 Replies
Oct 5, 2008
Working on an important piece at present; I need to make theimage wihtin a holder_mc go fullScreen, not the whole interface.Heres my code thus far:
masker.addEventListener(MouseEvent.CLICK, fullScreen);
function fullScreen(MouseEvent):void
{
[code].....
View 8 Replies
Aug 13, 2009
ActionScript Code:
_root.UpnDown_mc.up_btn.onPress = function () {
_root.Website_mc._y += 30;
[code]....
very simple code, you press the down button on the screen and the page moves down, and similarly for the up button, by 30 pixels...but it only happens once? I need it to continue for as long as the button is being held down.I have tried placing it within the onEnterFrame event, but it still only occurs once.
View 1 Replies
Sep 8, 2011
Is it possible to put a function into an array and execute it from calling it via the array?I did this before in as2 [code]
View 2 Replies
Dec 10, 2009
My flash piece is not responding when I mouse over it, unless I hold down the mouse button while I do it. It's as if the flash object is actively surrendering focus unless I hold down the mouse button or something.
View 1 Replies
Mar 12, 2007
Basically I wanna remove my mc "ball" when you press the left arrow key. I've tried stuff like
Code:
if (Key.isDown(Key.LEFT)){
ball._x -= 1;
}
Some reason gives me like, "needs clip events"
View 6 Replies
Aug 13, 2009
I'm trying to make a slideshow holding 3 images with 3 different categories. The images is loaded through an XML-file.
My xml looks like this: (the number after IMAGE[] indicates the category)
Code:
<?xml version="1.0" encoding="utf-8"?>
<SLIDESHOW SPEED="2">
<IMAGE1 URL="images/1.jpg"/>
<IMAGE1 URL="images/2.jpg"/>
[Code]....
View 8 Replies