How To Use Variable Inside Of Timer

Jun 18, 2010

I'm working on a simple catching game where you have monsters coming out from the corner of the screen and you need to get them with the mouse.What I want to do is change the rate at which the monsters come out depending on the score. The higher the score, the more monsters should come out.The code for creating new monsters is a simple timer event:[code]it works when I declare the variable locally within the function. But then I can't access it outside of it, so it's no good!

View 2 Replies


Similar Posts:


ActionScript 1/2 :: Timer / Delay Inside A 'for Loop'?

May 29, 2010

possible to have a timer that works inside a 'for' loop? I have created a timer but it only activates each time the frame is run through. I have a for loop with i++ so that I can put objects on the page with a small pause between them. The i++ loop puts all the movieclips on the page simultaneously. I need a delay and a loop because the shuffled arrays will be reset each time the frame refreshes.

View 1 Replies

Actionscript 3.0 :: Put A Delay Or Timer Inside Of A Function?

Aug 31, 2009

I'm trying to put a delay or timer inside of a function, ie:

Code: Select all
this_btn.addEventListener(MouseEvent.CLICK, doThis);
function doThis(event:MouseEvent):void
{

[Code]....

So that where I have the function for the button make that movie clip go to frame 1, it would wait one second before going to frame 1.

View 2 Replies

ActionScript 3.0 :: Variable Timer Functions

Mar 2, 2009

I am trying get a timer function that I can change the interval on? IE. I invoke the function for 5 frames and the last one I want to have a different delay time. It seems that for each action I have to create multiple listeners and multiple functions for? Surely there is a way, without producing a class, that I can just chaneg the timedelay? But, AS3 wants to declare the time before the function.

View 2 Replies

ActionScript 3.0 :: Set Variable Time For A Single Timer?

Jan 7, 2010

how to set variable time for a single timer, like I first setup this timer:

private function timer():void{
var randomTimer:Timer=new Timer(time,0);
randomTimer.addEventListener("timer", somefunction);

[Code].....

So how can I influence the time inside the timer? Do I create a global timer, remove the listener and recall the timer function? Would this work since the timer has already been declared, I a re-declare a timer?

View 1 Replies

Flash :: Getting An Error #1009 On A Timer Variable

Feb 22, 2011

I'm having Error #1009: Cannot access a property or method of a null object reference. I'm not exactly sure how to solve this problem myself, I've traced to see if the object var enemySpawnTimer:Timer is actually null and it isn't. So I don't understand why I'm getting this error.

Anyway here is my code, it's a class I use to spawn blocks that fall from the top of the screen to the bottom and is removed from the stage once it reaches the bottom of the screen.

[Code]...

View 2 Replies

ActionScript 3.0 :: Pass A Variable To Timer Function?

Oct 5, 2011

Is there a way to pass a variable to the timer function effectively changing the length of the timer when it runs.[code]...

View 2 Replies

ActionScript 3.0 :: Error 1065 - Variable Timer Not Defined

Dec 30, 2009

I've been practicing this tutorial: [URL] (Using the Document Class - how to use this new feature in Flash CS3 which makes OOP much easier.), and made my DocumentClass.fla and DocumentClass.as file. Both files reside in the same folder, D:Work\_FLA.
I have set all data that are pointed in tutorial - DocumentClass name in "Document class:" section in Document properties, ActionScript 3.0 language for .fla, "Star" as a movieclip name and Class in Symbol Properties.

And my as file is like:
Code:
Select allpackage {
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class DocumentClass extends MovieClip{
private var time:Timer = new Timer(100);
[Code] .....

Unfortunately, I get:
ReferenceError: Error #1065: Variable timer is not defined.
at DocumentClass$iinit()
In Output panel every time I try to export movie.

View 5 Replies

ActionScript 3.0 :: Capture The Timer Value To A Variable And Resume It From There At A Later Time?

Jul 8, 2011

I know how to stop and start a timer, but how can you capture the timer value to a variable and resume it from there at a later time? I tried capturing the currentCount of the timer to an integer variable, but i cant modify it.....it says its read only.

View 1 Replies

Flash - Timer Object With TimerEvent.TIMER Event Globally Accessible To All Objects?

Feb 16, 2012

I am working on a very simple game in Flash. I want to make all the animations framerate agnostic, so that I can change the framerate without affecting the flow and speed of the game.I read somewhere that if you want to do that, you simply create a Timer object and attach an event listener to this timer.

What if I have many objects that have to listen to the same timer? See the code to understand what I am trying to do. At this stage nothing breaks, but the event does not fire.Here is the Main class, the one that runs on swf execution:

public class Main extends MovieClip {
private static var _stage:Stage;
private static var _timer:Timer;

[code]....

View 1 Replies

ActionScript 3.0 :: Use A Variable Inside A GotoAndStop?

Mar 23, 2011

I saw a few examples when googling but couldn't get it to work. I want to use a variable inside a gotoAndStop. Is this possible?
 
[AS]
var vRandomNumber:Number = 1;
gotoAndStop(vRandomNumber);
[/AS]

View 3 Replies

Flex :: CDATA Inside XML Variable?

Oct 23, 2009

In Flex I want to create XML variable like this but parser complains about CDATA in publisher tag:

<mx:Script>
<![CDATA[
private var myXML:XML = <book>[code].....

How do I pass xml text with CDATA into XML variable being in MXML Script?

View 1 Replies

How To Pass Variable From Inside MovieClip Into Another One

Sep 29, 2011

I am creating a quiz and I set one quiz block with questions into a movieclip. When the person answers the correct answer I want it to add to a counter and pass that value onto the next movieclip. So movieclip one is added to the stage it does something then adds a counter. Then moves to the next frame and movieclip2 is added to the stage. It does something and add to the same counter variable from movieclip1. And so on and so on until no more movieclips.

View 1 Replies

ActionScript 3.0 :: Get Variable Name Inside An Array?

Jan 11, 2012

Is there a way to obtain the variable name that is inside an array?[code]...

View 2 Replies

Actionscript 3.0 :: Getting A Variable Inside A Funtion?

Jun 22, 2009

loader_ary[i].contentLoaderInfo.addEventListener(Event.COMPLETE, loadyLoaded);I would like to have access to the variable "i" inside the function loadyLoaded.what code would i need to useto return i or atleast the name of loader_ary[i] and slice it or something.

View 9 Replies

ActionScript 2.0 :: Targeting A Variable Inside A MC?

Jul 7, 2008

I have a movie clip called curtain_mc with this actionscript inside:

[Code]...

I would like to change the variable 'f' from true and false by clicking a button but the actionscript on my keyframe doesn't recognize the actionscript in my movieclip? I know its a targeting issue, but not sure how to alter it in order for the two to talk to each other??

View 6 Replies

ActionScript 3.0 :: Use A Variable Inside AddChild()?

Nov 30, 2009

Here's my (simplified) code:

Code:
var doorType:String = "DT0";
var openType:String = "OT0";
var imagePositioner:Sprite = new Sprite(); //Places a Sprite that will "contain"

[Code]....

openType is defined on a previous screen, it will be equal to OT1 or OT2. I have two sets of images (movie clips) that each have a prefix of "ot1_" or "ot2_" (in their class name). Other than those prefixes the two sets of image names are the same. I think I could cut the amount of code in half if I could use a variable when I use addChild.

I am not very knowledgeable of AS3 and everything I've tried has failed. My theory is that addChild() needs to contain a movieclip, so putting a variable name in addChild() doesn't work.

View 6 Replies

ActionScript 2.0 :: Set Variable With Quotation Inside?

Aug 17, 2004

I need to set a variable that displays quotation marks on the screen. I don't want to say 30 inches when I mean to say 30".

This is what I'm doing....

inches = "30""

obviously flash thinks I typed two "'s and is giving me a "String literal was not properly terminated" error... did a search with no luck and I can't find anything in flash

View 4 Replies

ActionScript 2.0 :: Dynamic Variable Inside Movieclips

Jan 21, 2011

I recently started learning Flash and Actionscript and now I'm trying to write an actionscript for the first time. Im doing this in Actionscript 2.0.I have a movieclip that consists of two images and one dynamic text field with a variable. The name of the images are "VS1_P1_RUN" and "VS1_P1_OFF" and the name of the dynamic text field is "pumptext". In the dynamic text field I have the variable "VS1_P1_Ind". VS1_P1_Ind is probably a boolean variable as it shows 1 or 0 in another program but in Flash it shows True or False (not sure if Flash thinks it's a text/word or a boolean).My script is supposed to display the image named VS1_P1_RUN if the variable of the dynamic text field pumptext shows the text True and it goes like this:[code]

So I'm completely stuck in what to do. The bottom code works as it should but I want the images to show depending on the value of the variable VS1_P1_Ind. I thought just changing the text field to dynamic and typing the variable name in the variable field would do it but no.If it could be a clue to the solution I'll also share that the value of the variable is not seen/shown in textfield while inside the movieclip. Creating a dynamic textfield outside of the movieclip shows the value of the variable just fine, True/False.

View 1 Replies

ActionScript 2.0 :: Load A Variable From The .fla Inside A Function?

Jun 2, 2011

I have some buttons in the scene (inside the .fla) that change a variable "counter" after being clicked. In a separate class there is a function "showPage" that loads a xml-file according to the value of the variable "counter". My problem is, that I dont get the variable "counter" from the fla-file into the function of the .as-class.

Here is my code:

Inside mcMain.as

Code:
class mcMain extends MovieClip
{
//public var counter:Number = 1; //Das hier soll durch den Button getan werden :(

[code]....

View 1 Replies

ActionScript 3.0 :: Creating A Variable Inside A MovieClip?

Aug 5, 2009

I need to create a variable inside a MoveClip. The easiest way to do this is to click on a movieclip in the editor and just enter the actionscript on a frame, but because i'm doing this with dynamically created movieclips i need to do it with actionscript.
 
PS: I'm doing it for sorting purposes in a slideshow.

View 3 Replies

ActionScript 1/2 :: Variable Inside 'for' Loop With Parenthesis

Sep 5, 2009

how Im going to put the i variable inside the [[[[ ]]]]] because I cant make it work for(var i:Number=0;i<products;i++){  _root.menu["product"+i]._x += (product[[[[[+i]]]]]x-_root.menu.product["product"+i]._x)/speed; }

View 5 Replies

ActionScript 3.0 :: Getting Variable Value From Inside Of Event Function

Feb 29, 2012

How to get variable value from inside event function. Variable was declared outside event function.
var StringVar="sample";
myButton.addEventListener(MouseEvent.CLICK, myClickReaction);
function myClickReaction (e:MouseEvent):void{
StringVar="other sample";
} trace(StringVar); /*

It gives me "sample" value and I would get "other sample" value */. That strange because if that would be normal function trace would give me good result.
var StringVar="sample";
function myClickReaction():void{
StringVar="other sample";
} myClickReaction();
trace(StringVar); /* it gives me result as I wanted to have - "other sample" value */

I know also method of passing arguments into event fuction but it not works for me as I would like to
var StringVar="sample";
myButton.addEventListener(MouseEvent.CLICK, function(e:MouseEvent){ myClickReaction(e, StringVar) },false, 0, true);
function myClickReaction (e:MouseEvent, StrVar:String):void{
StrVar="other sample";
} trace(StringVar); /* it also gives me "sample" value and I would get "other sample" value */
How to do that correctly?

View 11 Replies

Flash :: Call Variable Inside A Function ?

Sep 25, 2011

I'm trying to pass a variable through a function, but I'm getting it's value 0. Here's my code:

thumbLoader.addEventListener(MouseEvent.CLICK, goToCategory);
function goToCategory(e:MouseEvent) {
trace(c);[code]....

this trace gives me value of 0. Normally I would do goToCategory(c) and inside that category I would get it's value, but in this case I'm calling this function with an event, how can that be done?

var c is declared globally, so I'm using it above this code in different place... is there smth like global $c like in PHP.. or there's some other way to do it?!

View 2 Replies

ActionScript 3.0 :: Variable/Array Inside A Hit Test

Oct 22, 2009

I have three randomly moving movie clips and one keyboard controlled movie clip which is meant to avoid the tree random flying clips.

I want to do a hit test that basically will do something if anyone of the 3 random clips hit the keyboard controlled clip.

in the hit test i want to be able to have this work for any of the three random clips (flying pumpkins with different instance names, pumpkin1 pumpkin2 pumpkin3). This is all done on an external document class.

I thought about an array but I have no idea really

package{
import flash.display.MovieClip;
import flash.events.*;
import flash.display.*;

[Code].....

View 0 Replies

ActionScript 3.0 :: Access A Variable From Inside A Function?

Dec 8, 2009

i am trying to access a variable from inside a function like this:

ActionScript Code:
var X:Number=1;
function hello(event:event){
trace(X)
}

or something like that... does anyone know why i don't get "1" in the output panel when i run the code?

View 3 Replies

ActionScript 3.0 :: Changing Variable From Inside Of Function?

Jan 9, 2010

I have a code, it is below. And i have two vars: coordx and coordy they both are 0 but when up button is pressed, coordx should change into 1 x remain 0 just like map scrolling and if pressed down it should return to default position, but instead of that variables keeps reseting and it starts from beggining. Here is the code:

ActionScript Code:
var coordx:Number = 0;
var coordy:Number = 0;[code].......

View 3 Replies

ActionScript 2.0 :: Variable Referencing Inside Loops?

Apr 27, 2010

ActionScript Code:
function setUpButtons() {
var btnCnt = numeri_array.length;
for (i=0; i<btnCnt; i++) {

[code]...

i'm having a problem with this script... the onRollOver and onRollOut are working properly but the onRelease it's always the same i mean (my_mc.loadClip(foto[27], "container") for all the 27 buttons..

ActionScript Code:
for (i=0; i<btnCnt; i++) {
var temp = this["a"+i];

[code]....

and everytime i have to make a modify i have to write for every case..

View 2 Replies

ActionScript 3.0 :: Change Variable Inside A Function?

Oct 19, 2010

How can you change a variabele in as3 that you have declared OUTSIDE a function and change it inside the function.My function seems not be able to change the variabele?

ActionScript Code:
function Filter2switch(event:MouseEvent) {
if(filter2 == false){

[code]......

View 1 Replies

ActionScript 2.0 :: Load Outside Variable Inside Movieclip?

Apr 18, 2004

I have a movie clip that needs to load an outside Variable and I know how to do it if the Variable is in the main time line.

Main TimeLine:
timedelay = 5;
MovieClip
timedelay = _root.timedelay

What I can not figure out is how to load a variable in a movie clip that is on the Instance of itself (not in the movie clip).

I am fine if I only use one instance of the movie clip at a time on the stage since I can set the Variable on the Main TimeLine into the movieclip (using .root), but this would not work correctly if I want two instances of a movieclip with differenct variables.

Right now I am having to make duplicate copies of a movie clip with different Variable names. I was hoping there would be some way where I could only use one movie clip and give it different variables.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved