ActionScript 2.0 :: Object Placed Randomly In An Array?
Jan 26, 2010I'm building this simple platformer (one level, block graphics, just to get the basics down). I have this array system set up:
[Code]....
I'm building this simple platformer (one level, block graphics, just to get the basics down). I have this array system set up:
[Code]....
the code below loads only the second member of the "koan" array. why it isn't randomly loading swfs? (Could it be a problem with the "var index"?...when it is changed manually in the code from 0 to another number the swf played does change; but still not randomly.)
[Code]...
I have an issue where I would like to remove a sprite randomly in AS3, I have managed to figure out how to create the sprites so that they fill as a grid, just for the life of me I can't figure out how to remove them!Here's the code i've used to create them:
function showpixels() : void
{
for (var i:int = 0; i < 40; i++)
[code]......
I am trying to write a function that is passed an array and will then reorder it randomly and return the array. My problem is that as the position is generated randomly I dont know how long the loop must run for, this function doesn't work but it should give you an idea of what I'm trying to do:
[AS]
function randomise(the_ar:Array):Array {
var ret_ar:Array = new Array();
for (i=0; i<200; i++) {
[code]....
How can I make my Array to return a randomly value? I want AirUnit to return a value between 1 and 3. I want LandUnit to return a value between 4 and 6. I want WaterUnit to return a value between 7 and 9.
View 1 Repliespick 1 element in array randomly ONCE
View 1 Repliesis it possible to have an array of words, and then, with another set of code, to have those words randomly animating (perhaps from the distance, to closer up, like a zooming non-blurred effect) on the stage?
View 3 RepliesI am trying, with this code, to first, shuffle the order of the images in the array so their loading sequence is never the same when the page is reloaded.Then, im trying to have the shuffled array open one at a time, image by image, at a set interval.
Code:
Array.prototype.shuffle = function() {
for (i=0; i<this.length; i++) {
[code].....
I understand how Math.random works, and I understand how Arrays work, but I don't understand how to either rearrange the indices of an existing Array, or how to populate it from another Array in a random sequence without an index possibly repeating.
View 2 RepliesOk what i want to do is to randomly pick 3 values from an array called Objs and add them to a new array called ListObjs. The three values should be unique. This is the code I have so far, but when i try to execute it Flash stops responding.
[Code]....
I'm would like to use the UILoader to randomly load an image from an array according to the day of the week. The attached FLA file is in AS2, it is exactly what I would like to do but now in AS3. I've been able to successfully trace the date using:
var today_date:Date = new Date();var dayOfWeek = today_date.getDay();trace(today_date.getDay());
In AS2 I used this the loadMovie function to randomly display SWF's in the movieClip. From what I can tell loadMovie is not an option in AS3 making me think that using the UILoader may be a good solution.This is what my code looks like in AS2 (also attached the FLA file):
loadShow = function() {
var today_date:Date = new Date();var dayOfWeek = today_date.getDay();trace(today_date.getDay());[code]....
Is there some basic AS3 code to have, when the swf loads, a single video play from a collection of videos in an array? And can said code also apply to sound without video?I just found out the tutorial I was using to randomize doesn't work with audio - as it just plays everything at once - you might 'see' one video - but you hear all them. So from what I am reading, I need to us an array (that seems simple enough), but I don't want to play all the clips - I want it to randomly select and play one. Not sure exactly how I set up the video playback area (so the video plays where I want, at the size I want).Also, I have other pages that are just audio - does audio need some sort of player or something for this?
View 6 RepliesI want to create an array of loaded xml for the following:
ActionScript Code:
var xmlQuestions:XML = new XML();
System.useCodepage = true;
[Code].....
What I want to achieve is so I can load 5 different xmls and place them into an array. All 5 random xmls will be placed in an array then I wish to trace them
Let's say I wanted to randomly remove an item from an array in a for loop.
Basically, it would go something like;
thearray = ["lol", "dude", "ROFL", "lame", "excellent"]
for (i=0; i<4; i++) {
randomness = random(thearray.length())
thearray.remove [randomness]
}
Obviously that last line was made up, that's where the code goes for the item-removal.
I cant seem to find the code to make an object randomly fall from some random y, or the code for if this object hits an instance then goto another frame?
View 1 Repliesso i am having trouble with adding a box randomly on the screen. I have done this before and it seems like it should have a relatively easy solution. But alas, i have not been able to figure this out. This is the info: I have a box mc with exporting as Box. I have a Box Actionscript file with this code in it:
[Code]...
Nothing happens at all but there is no errors. Also i would like to keep everything in the classes.
On my previous post Adding a object randomly on the screen in as3 I explained the specifics of my situation. But I will go over it again. I have a box with a class(not my document class. I do have one called Main but this one is just an AS class referencing my box.) The classes name is Box and my MC box is exported as Box. This is the codethis is in my main file on the main timline
addEventListener(Event.ENTER_FRAME, createbox);
var _box:Box = new Box;
var boxlimit:int = 2;
[code].......
[url]...
I'm trying to make the text elements (graphics) in the above link shake. Barely, randomly, and sporadically. Just enough to get somebody's attention.
Anyway, I've used flash a couple times, built a couple flash websites, but nothing much with ActionScript. I figure AS would be the best way to do this, since I might repeat this on other elements within this website.
Hi, I am tring to make an object move across the screen randomly..I want it move up-down left or right acording to the values created..for example I want my object move between value (-5 and +5 ) whats wrong with this ? because it always moves downward ???
[Code]...
I've been working endlessly to figure out if there is a method to make an object move randomly. I know there is a way, because I have seen many sites using it. Yet, I am unable to create anything besides specified movement in the x and y values. I can't make anything move randomly.
View 14 RepliesCan images be stored in some sort of array and then called to the stage randomly?
View 3 RepliesI have a simple .fla file with a circle on the stage. I want to set actionscript to make the circle randomly change colors when playing. I've tried all sorts of script commands using math random but to no avail
View 4 RepliesWhat I have is a ninja star that spins around and moves based on the accelerometer of your phone. I created a balloon popping animation and have it all working well. The problem is that as of right now I can either have it be static and animate once the ninja star hits it, or I can have it randomly move and then play the animation which is not what I want. I want it like this: When the ninja star hits the balloon, the animation of it popping plays. And then once the animation is complete, then I want it to randomly move to a new position on the stage. (so the user can hit it again, and so forth...)
Here is my code so you can all take a look.
import flash.sensors.Accelerometer;
import flash.events.AccelerometerEvent;
import flash.events.Event;
var my_acc:Accelerometer = new Accelerometer();
my_acc.setRequestedUpdateInterval(50);
[Code] .....
i need to make an object move randomly around the stage on the click of a button and then stop the object using a different button
View 2 RepliesI'm trying to make an object to move randomly across x-axis and while it moves back and forth it also scales in width.
View 3 RepliesIm attaching cards to stage in random positions using arrays. I'm having some coding issues randomizing so when I refresh the swf the cards numbers should change randomly but are not. This is my code:
var cardList:Array = new Array();
for (i=0; i<16; i++) {
cardList[i] = "card"+i;
}[code].....
I found this code online. it is for a image gallery that fades in and out as it transition from one image to the next.. the images are load through an array command... it loads the first image, etc.... what I wanted to know is where should i put a Math.floor(Math.random()*this.pic_arr.length); in the string of code... to make the gallery start randomly in the array and then continue onto the next image... also, for some reason, there is not a common directory for all the images, like this script:
[Code]...
Is there anyway to randomly place a MovieClip/Sprite on an irregularly shaped object?For a rectangle, it seems pretty straightforward (i.e. use Math.random with the range being the coordinates of an object)...but what if say, you would like to avoid placing objects in the center?
View 2 RepliesMaking a ship game because I am incredibly original.. With that aside, I have a problem. I have a function to fire bullets from my ship based on its rotation which works.. it uses this code on creation: ember ho jis ny mmujhe block kia hai
[Code]...
The above code is in my Ship class so I can easily make the bullets achieve the correct rotation. And to continually update its position, in the bullet's class:
x += Math.cos(rotation / 180 * Math.PI) * speed;
y += Math.sin(rotation / 180 * Math.PI) * speed;
So that all works well. But I have another class, EnemyBullet, which randomly generates and uses similar code to set its direction and movement. In my ship class:
[Code]...
I gather that the rotation is therefore always horizontal, but can't for the life of me see why? Can anyone give me an answer? Assuming it's simple enough because the code I used to setup the rotation is the same working code I have used to turn a movieclip towards the mouse..
I've managed to get a sensor attached to an arduino talking to flash using something called AS3glue. it works, when i set up a trace("leaf") for the contition that the sensor reads 0, i get a printout of the word "leaf". however i want the program to make a graphic appear on the screen when this condition is met, not just trace something.
I'm trying to get the program to generate a library object called "Enemy" on the screen at a random position each time the conditions are met. It's called enemy because I was following a game tutorial...actually it's a drawing of a leaf. Here's the bit of the code which is causing me problems:
[Cdoe]...