Actionscript 3 :: Flash Cs5 - Instantiating Objects With A Timer?
Jul 25, 2011
I'm making a vertical (constantly) scrolling shooter & am trying to instantiate objects based on a timer. For example: At 30 seconds, place a building @ x, y. My problem is that the "building" is instantiated when the game starts and then again at the 30 second mark - instead of only @ the 30 second mark. If anyone could steer me in the correct direction,
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;
I'm looking to load external .swfs that have graphical assets in them which are all 'exported for actionscript', and instantiate those assets in a .swf packaged for iOS. I'm using the adt command line packager to create the .ipa file. I'm including the .swf files while packaging. The .swf files seem to load correctly, and give me no errors, but when the Loader for each .swf's bytesLoaded equals bytesTotal the content property remains null.The program works perfectly when I package the .ipa using the -target ipa-test-interpreter flag, but not when I use the -target ipa-test.
I'm assuming the problem is that iOS doesn't allow Flex developers to load external .swf files that contain actionscript, and the 'export for actionscript' in the external .swf files counts as actionscript for the purposes of Apple's security policies. I'm looking for confirmation as to whether or not this is the problem.When using adt to package .ipa files, does iOS block external .swf files that have library assets that have been 'exported for actionscript'? [URL]
I quickly realized that instantiating all movieclips in the document class all at once is probably not a good idea. I want to call movieclips from the DisplayList, instantiate them when needed. How do I go about on doing that.
I have this class named MovingObject which extends the MovieClip class. This class will be instantianted for several times. Inside this class is a Timer that handles the speed of the objects moving. There is another class called TheStage and this is where I will instantiate MovingObject (s).
public class MovingObject extends MovieClip{ public var tmr:Timer = new Timer(1); public function MovingObject(){
[Code].....
Assuming that the code is working fine (I haven't debugged it), this makes the particles to move all at once. However after several seconds of running it, the particles seem not to be moving in synchronization with each other (because their distances between seem to get nearer).
I am adding a Timer object when my flv playback enters a Pause state and removing that Timer Object when playback starts again. I noticed that if I pause the movie and then drag the slider on the timeline the movie enters the Pause State again which adds another Timer Object....
How do I check to see if the Timer has already been added and if so remove it and add a new one.
See code below:
my_player.addEventListener(VideoEvent.PAUSED_STATE_ENTERED, pausePlay); my_player.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, startPlay); function pausePlay(e:VideoEvent):void {
I have an animation of footprints being left on the ground as if by an invisible man or ghost. the animation consists of:
1 movieclip containing --> 5 footprints each one is an individual movieclip. Each print fades in and out using the Tween class with an alpha effect
The main timeline uses the following code to create random instances of the animation:
var myTimer:Timer = new Timer(12000); myTimer.addEventListener("timer", timedFunction); myTimer.start();
[Code].....
so it looks like the function is being called correctly and removing the first instance of FOOT from the stage. but the 2nd iteration generates the error. Is this is a problem with the timer? I would like to send this to someone for examination and assistance.
I am trying to use AMF PHP to pass variables to a flash file, thus far I cannot see anything wrong with my code, but I have very little experience with creating classes, so here it goes, here is my code,
index.php:
<?php include "amfphp/services/flashMe.php"; $session = true;
[Code].....
Flash is looking for the flashMe class and the push method within that class, but I keep getting null variables in my flash file when I run it
Not only am I a newcomer to these forums but I'm also very much a newcomer to ActionScript, so I hope you will have some patience if you are able to provide me with a crystal clear answer to my problem and I'm still a little lost! Basically, I have made a flash game where the player moves around on screen and tries to collect a little ball. There a timer on the ball that counts down to 5. One of two things can happen from here: 1. If thetimer reaches 0 before the player collects the ball, the ball is moved to a new random location, the players "lives" count goes down by 1 and the timer goes back up to 5. 2. If the player collects the ball before the timer reaches 0, then the player's "score" count goes up by 1 and the ball moves to a new location with the timer going back up to 5.
Is there a way I can load a swf file but not automatically instantiate it's DocumentClass? Instead I want to do something like the following: protected function mainLoaded(e:Event = null):void { trace('mainLoaded'); var main:* = this.mainLoad.createClassByName('Main'); trace(main); } Where mainLoad is an instance of CasaLib's SwfLoad and createClassByName is the equivalent to loaderInfo.applicationDomain.getDefinition(); The thing is that when my swf finishes loading I can see it is created, because of some trace calls, although its obviously not added to the display list.
After adding an image to the stage, turning it into a Movie clip, and setting linkage in library to Export for Actionscript, I'm now using a timer to add a bunch of roses to the stage as a video plays.How can I get rid of all these clips once the video is over?Do I need to add all of them into an extra container and then just removeChild that container at the end? Or do I need to use something like getNumberOfChildren and then create a loop that removes them one by one?The clips (myRose) are fairly small and do not have any event listeners added to them. I just use TweenMax to move them from top to bottom of the screen.
public function roseTimer():void { MonsterDebugger.trace(this, "in roseTimer");[code]......
I have a symbol named picHolder. In symbol properties under linkage, I chose "Export for ActionScript" and "Export in frame 1" and gave it a class name of picHolder.Normally, to instantiate a new instance, I'd say:
Code: var tempPic:picHolder = new picHolder(); and I'd go about my way.
Can I access a static variable of a subClass' subClass? I don't want to instantiate it, just looking to get the variable because it has already been initialized by the subClass.example:
package { public class A extends MovieClip { private var classB:B = new B();
We used to write our UnitTests with FlexUnit and we were just testing our model. Now we want to test the view too. Before i run my tests i create an instance of my view and my model to test the stuff. When i try to access the view i get a null pointer exception. If i add the view to the displaylist it somehow works - even if i remove it from the list right after adding.it looks something like this:
var myView: MyView = new myView(); //myView.initialize(); will throw error Application.application.addChild(view);[code]..............
i've been struggling with one problem for weeks, and i've just found what i think is a possible cause (or at least a contributing factor)
This line:
Code: var totalOffset:Point = rangedWeaponData.totalOffset;
What i thought it was doing is creating a copy of a static variable, for me to manipulate. However my debugging seems to show so far that it's actually creating a reference, and my subsequent manipulation of that is also manipulating the base variable it references.
Code: var totalOffset:Point = new Point(rangedWeaponData.totalOffset);
My Class B imports Class A.Class A is associated to an FLA. This FLA has a moviclip (MC) in its library.Now I need to dynamically instantiate that movieclip MC from Class B. How can I do that??
When I set the following class as my document class it works (draws a rectangle) but when I don't set it as my document class and instead instantiate it using var myRec:simple_shape = new simple_shape(); in first frame of my timeline nothing happens no rectangle and no error either). why and how I can get it to work without setting it as my document class?
I asked yesterday how to call a function from an XML file, and I figured out how to make that work using the string-to-function call.so in my XML file I have <ITEM CALLBACK="ContactsList">View All</ITEM>, and my TextMenu class parses the XML file and creates my navigatable text menu instance. When enterMenu():String is called, it looks to see if the CALLBACK attribute has a value, and if so it returns it as a String.so..
var callbackFnc:String = textMenu.enterMenu(); if(callbackFnc != null) {
Is there any difference in performance, or instantiation speed, between the two? Will anything be different in the instantiation of the MyClass object?
public class MyClass { private var _myObject:SomeClass = new SomeClass();
I've noticed that using large jpg;'s that are highly compressed take a lot of time to appear as a mc on stage after calling " new mcname();"
I have doubled my background from 1500X900 to 3000X1800. I use a movieclip in library containing the .jpg source image. Creating the larger one takes about 5 times longer to appear. Kicking my levels start from about 4 seconds to a 20 second wait.
I am loading one swf into another using the Loader class, but when the child swf finishes loading and is added to the display list, its Document Class is not instantiated. I have a few trace statements that should execute when the object is created, but nothing is happening when loaded into the parent SWF. When I compile the child SWF on its own, the Document Class runs as expected.
So I'm wondering... how do I associate a child SWF's Document Class with Loader.content?
You can right click and see the source. 1.) How can I instantiate the bricks without taking such a big performance hit?
a.) currently, I�m instantiate the bricks that make a column one at a time. I tried doing this with a repeater which did work but I could not get the animation to work on each individual brick. The animation would only work across the entire column.
2.) How can I get the UIComponent that contains the brick columns to align itself to the vertical bottom 10 pixels above the box along the bottom with the slider?
a.) I'm currently adding a UIComponent to the stage dynamically and then keeping a reference to that UIComponenet, I am adding my bricks.
3.) How can I improve the animation?
a.) Most of my research has suggested the only way to animate a sprite is to use a Timer() or connect to the onEnterFrame event.
I've got a confusing situation which wont seem to fix itself basically I have my main class, my iContent class (which will hold each page and have functions for all pages), and my individual pages.
The homepage is instantiated by calling the iContentClass.goHome method in the main document class. The home page contains a button to go on to the next page. This button references the goColourBrowserPage function within the iContentClass, which removes the child (being the home page) and attempts to add a child (colourBrowserPage).
For some reason this doesnt work! It doesnt seem to add the child and wont let me remove the child of the home page! I've been sitting here for 3 hours trying to work it but to no avail!
What is the difference between Timer.stop() and Timer.reset() functions because it seems that the 2 functions do the same thing? I image Timer.stop() to stop the timer and when Timer.start() is called the timer starts from where it stopped. For example, if I have a 3 sec. timer (3000 ms). If I stop the timer after 2.5 sec. and start the timer again, I would expect the timer to expire/trip within .5 sec.
I have a ActionScript 3.0 project and I have a timer that is running on 1000 millisecond intervals. I would like to delay this timer for 1500 milliseconds perform an action and start the timer again after the delay. I thought I could do this easily, but I'm having trouble, would it be better to stop the timer and perform the action and then listen for the action to be completed to start the timer again?
In my case, the timer I make doesn't reduce its time whenever a function is called. What code will I change or add in order to reduce the time in my timer? [code]At this point the timer.start(); is placed on a frame so that the timer starts as it enters the frame.