ActionScript 3.0 :: Do A Math.random On Selecting A Certain Number Of XML Items?
Jul 5, 2009anyway to do a Math.random on selecting a certain number of XML items?
View 8 Repliesanyway to do a Math.random on selecting a certain number of XML items?
View 8 Replies1) what value is seeded to Math.random() to generate the random number?
View 2 RepliesHow can i create a random number without using Math.random() I think this can be done with a array... i just don't know how.
i need it for a google banner. they don't allow Math.random() of random() in the sript
So what I have here is a button that will take away a random number from a variable (in this case being money) this is nothing more than a learning experience and I just wish to broaden my horizons on flash AS.
Actionscript Code:
on (release) { money -= random(200); }on (release) {gotoAndPlay (2);}
While this code works just fine the only problem i have with it is that it will select a number from (0-200). Is there a way I can set this up to select a random number BETWEEN 2 numbers? EX: (150-200)
I don't get it. I know it's Math.random(), but how do U use it. Let's say I want a number between 10 and 70.
View 4 RepliesI have created a tween with actionscript that moves a movie clip of a cityscape along the x axis whenever the mouse is clicked.
This is my code
var skylineTween:Tween=new Tween(skyline_mc,"x", Regular.easeInOut, skyline_mc.x,Math.floor(Math.random() * (-1022 - -16) ) + -3,2,true);
Right now it generates a random number from between -1022 and -16 (positions along the x axis).
However, sometimes the skyline movie clip only moves a few pixels and looks boring.
I added 200 pixels to the movement (Math.random() * (-1022 - -16) +200 ) and it looks better. However, sometimes this slides the movie clip past -1022 or -16 and off the stage.
How can I set the value to +200 without passing -1022 or -16?
I'm trying to play a random gallary image by making it stops at different frame every few seconds, and the actions is completely random.
The problem is, since there are only 5 different images(5 frames) I'm displaying, there is a high probability that it stays at the same frame, how do I avoid that? Like avoid staying at the same page twice, if not run the function again.
[Code]...
I would like to use the selectionMode=multiple described in the Flex docs, but with a few modifications:
1) I would like the box that the user drags over the graph to remain there until the user drags a new one.
2) In the top right corner of the box I want to display the sum of the items selected by that box.
I've been putting data into an array via XML, and then selecting at random an image string to load in a pic at random. But whilst doing this, I wanted to remove the String from the Array that I have just used, so I don't get repetition of the same image in the output. I initially thought that pop would remove the string I had just used - But of course it Removes the last value in the Array instead, which doesn't really help.
Ok - so how about randomizing the data once inside the Array, after it has been pulled in from XML!? That way I can load in the 'last' image, and then pop it out! Keeping a randomized selection of images each time 'it' is loaded
am creating a little game... It is about selecting some items...If 2 right items are selected on frame 1, the "next" button will appear for the user to click on it to go to frame 2.
View 1 RepliesI'm trying to build a portfolio gallery.I have it set up so that the user gets all my portfolio items to start with and then at the top right there is a comboBox that allows the user to select "programs", "code" and "clients" this changes the left vertical tileList to only show icons of the programs or of codes etc.I'm trying to get it so the user clicks on one of the program icons or whatnot and it then limits the thumbnails in the tileList on the bottom of my widget.The thumbnails come from a xml document that has the images and then <keywords>.Inside this node is a list of the programs and codes used.I tried using indexOf and then a if statement to check if indexOf was -1.But that didn't work.[code]
View 2 RepliesSo you start off with all of the items in the inventory. You do not have to collect them.I have 8 MovieClips on the stage each with a different instance name. I made a class called Rebound and linked all the inventory MoivieClips to the Rebound class as the base class. they each have their own unique class.What I'm trying to do is select one of them. when you release the mouse off the movie clip (MOUSE_UP)it goes to frame 2 of its movieclip and making a variable I made up called isSelected = true.but when you click another item in the inventory I want it to deselect the item you clicked first so it goes back to frame 1 and isSelected = false. The problem I'm having is that it selects the first item when you click it. But when I click another the first stays on frame 1 and isSelected stays true. So if I click all 8 in a row they all become selected.[code]I thought this. called on every movieclip of the Rebound class?So instead of this. if there is something that can choose all of the movieclips that belong to the Rebound class I think I could use that instead. If there is such thing.
View 1 RepliesSo you start off with all of the items in the inventory. You do not have to collect them.
I have 8 MovieClips on the stage each with a different instance name. I made a class called Rebound and linked all the inventory MoivieClips to the Rebound class as the base class. they each have their own unique class.
What I'm trying to do is select one of them. when you release the mouse off the movie clip (MOUSE_UP)
it goes to frame 2 of its movieclip and making a variable I made up called isSelected = true.
but when you click another item in the inventory I want it to deselect the item you clicked first so it goes back to frame 1 and isSelected = false. The problem I'm having is that it selects the first item when you click it. But when I click another the first stays on frame 1 and isSelected stays true. So if I click all 8 in a row they all become selected.
here's the class
Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
[Code]....
I thought this. called on every movieclip of the Rebound class?
So instead of this. if there is something that can choose all of the movieclips that belong to the Rebound class I think I could use that instead. If there is such thing.
I have 8 MovieClips on the stage each with a different instance name. I made a class called Rebound and linked all the inventory MoivieClips to the Rebound class as the base class. they each have their own unique class.What I'm trying to do is select one of them. when you release the mouse off the movie clip (MOUSE_UP)it goes to frame 2 of its movieclip and making a variable I made up called isSelected = true.but when you click another item in the inventory I want it to deselect the item you clicked first so it goes back to frame 1 and isSelected = false. The problem I'm having is that it selects the first item when you click it. But when I click another the first stays on frame 1 and isSelected stays true. So if I click all 8 in a row they all become selected.[code] if there is something that can choose all of the movieclips that belong to the Rebound class I think I could use that instead.
View 7 Replieswhy is this code NOT loading a random image, despite tracing random number?
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.URLRequest;
import flash.display.MovieClip;
[Code]...
What I want is for my mc to slide to a new random x position when it is less than 5 pixels away from its target, it keeps doing this. the problem is for some bloody &*�$(()** reason my random numbers only keep going up!! why is this?? i want to produce random numbers between 1 and 770 - this is my code..
[Code]...
I am now using the code for my background image which will rotate when you enter a new gallery.I can't get it to randomize.[code]I have tried adding: Math.floor(Math.random() * total); and it almost works. It seems everytime the last node is called it stops working (also at other random times, haven't found a pattern).
View 1 RepliesSo you start off with all of the items in the inventory. You do not have to collect them. I have 8 MovieClips on the stage each with a different instance name. I made a class called Rebound and linked all the inventory MoivieClips to the Rebound class as the base class. they each have their own unique class. What I'm trying to do is select one of them. when you release the mouse off the movie clip (MOUSE_UP). It goes to frame 2 of its movieclip and making a variable I made up called isSelected = true. But when you click another item in the inventory I want it to deselect the item you clicked first so it goes back to frame 1 and isSelected = false. The problem I'm having is that it selects the first item when you click it. But when I click another the first stays on frame 1 and isSelected stays true. So if I click all 8 in a row they all become selected.
Here's the class
Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Rebound extends MovieClip {
public var isSelected:Boolean;
public function Rebound():void {
this.addEventListener(MouseEvent.MOUSE_UP, starting);
[Code] .....
I thought this. called on every movieclip of the Rebound class? So instead of this. if there is something that can choose all of the movieclips that belong to the Rebound class I think I could use that instead. If there is such thing.
I have an array of items that should be selected in my tree control. As you can see from my code below, I bind this array to the selectedIndices property of the tree. The selected Items are not properly selecting in tree(selecting some other items and always root is selected).Flex seems to "ignore" my items (selects some other indices).
My XMLList:-
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<fx:XMLList id="XMLList">
<node><node name="max">
[Code] .....
Like the title sugges¦ Is it possible to srand Flash's Math.random?I'm asking because I'd like to generate psudo-random numbers in a repeatable way.
View 2 Repliesbasically I want my engine to display one out of three objects at random. I thought I had figured it out but apparently not. A familiar error message appears, "A term is undefined and has no properties". I'm sure it refers to the object I'm trying to spawn, however it rejects every object I refer to. Is my approach reasonable or should I scarp what I've got?
Code:
var spawnObject:Array = new Array("Object1", "Object2", "Object3");
var randomNumber:Number = Math.round(Math.random() * (spawnObject.length - 1));
if(spawnObject[randomNumber] == "Object1")
[Code].....
Is it possible to randomly select from variables in action script?I have tried using or -
question.text = question1 || question.text = question2;
I have an app I'm creating with Flash CS5.5 with 42 different short stories in it. It has 2 scenes. Scene 1 is the opening and contents menu to access the stories. Scene 2 contains the 42 stories.In scene one, I have a button that I want to be able to pick a random story so it would need to pick a random frame between 1 and 42 in scene 2. I have seen some code in here that will pick a random frame when you open the program, but I don't know how to tie it to a button or pick a random frame in another scene.
View 14 RepliesDear Guys I Want To Generate A Random Number Between 2 Number BUT Without Generating 2 Same Number I Mean If For Example Already Generated Number "2" Next Time Did Not Generate It , Is There Any Solution
View 5 Repliesi have a collection of movie clips (mc0, mc1, mc2...etc etc),and when motion is detected on a webcam, one of these clips is shown on the stage. however, for some reason only mc0, mc1 and mc2 are being displayed, and i cannot get mc3, mc4 or any more to be chosen.
Code:import flash.filters.*// Assumes a Video object named "myVideoObject" is on the Stageactive_cam = Camera.get();filterList = [ /* 0 */ "multiply", /* 1 */ "multiply", /* 2 */ "multiply", /* 3 */ "multiply", /* 4 */ "multiply" ];positionList = [ /* 0 */ {_x: 512, _y:
[code]....
I know this should be easy, but I can't seem to make it work. All I want is for the variable currentPage to select randomly from an array so that every time the page loads, it displays a different currentPage. This is what I have so far:
var myImages:Array = new Array("outsource_mc","solutions_mc","staff_mc");
var randomImages:Array = [];
var randomCount:Number = 1;
var r:Number;
for (var i = 0; i<randomCount; i++) {
[Code]...
I've got a map that you can zoom in and out of. What I'd like is that are you zoom into the map the labels marking items on the map remain the same size. Initially I did this successfully by making the labels independent movieclips(ie not children of the map mc) and then using localToGlobal to make sure they were in the right position. However I found that there was a bit of lag in their movement compared to the movement of the map.
So I thought what I'd try is to make the labels children of the map and then scale them up and down inversely to the scale of the map. However I haven't been entirely successful. I'm having difficulty finding the equation to make it scale up and down correctly in proportion to the map. The problem is that my labels are scaling in a linear fashion while my maps scaling isn't.
[Code]....
How do I get a random number between 0.8 and 1.2 using Math.random(); ? It would be nice if you explain.
View 1 RepliesI Want To Generate A Random Number Between 2 Number BUT Without Generating 2 Same Number I Mean If For Example Already Generated Number "2" Next Time Did Not Generate It,
View 4 RepliesI'm generating a random number between min and max with this code:return min + (max - min) * Math.random();And it works. However, the random numbers are very little usually between "1 or 3" even if the max is 80.
View 3 Replies