ActionScript 3.0 :: Randomly Place X Number Of Rectangles On Stage?
Aug 13, 2009how could I randomly place x number of rectangles on stage so that they dont overlap?
not tween, just place?
how could I randomly place x number of rectangles on stage so that they dont overlap?
not tween, just place?
I'm trying to break up a square or rectangle into a large number of randomly sized squares or rectangles so that none are overlapping.How to fill a square with smaller squares/rectangles?The solution seems to be either through bin packing or some sort of tree map.But what I'm looking for is the actual algorithm in Java, Javacript , actionscript or even C.
View 3 RepliesI want to load some mcs randomly on the stage, except for a footer area at the bottom of the stage. Is there a way to exclude just a certain part of the stage using something like Math.random()*Stage and then specifying the bottom 300 pixels as off limits?
I'm using the whole stage because the swf is embedded 100% across the browser, so I can't restrict the dimensions.
Code:
onClipEvent (load) {
x = this._x=Math.random()*Stage.width;
y = this._y=Math.random()*Stage.height;
}
I'm trying to figure out how to tile a rectangle (the stage) with an arbitrary number of rectangles. Simple tiling where all the tiles are the same size and simply stacked in a grid.I'm doing this with a resizable layout and a number of tiles that is arbitrary and will change over time.
Given a more or less 4:3 or 16:9 monitor I would like a solution that tends toward minimizing the perimeter of the tile and being similar in aspect ratio to the screen. I realize that if I have a prime number of tiles that I won't be able to make a nice grid, but other than that it seems there should be some way to do this.Lets say I have 231 tiles I need to arrange. The factors are 1, 3, 7, 11, 21, 33, 77 and 231.If the screen is really, really wide 1 x 231. Wide but not not as crazy wide as before 3 x 77. And most likely 11 x 21 is what I would need.So is there an easy way to do this on the fly? Is there a pre-calculated way to make it easy?
I want to create animation. I want to slice image into random number of rectangles (it can't be squares) and I want to animate all of this rectangles at once.
View 2 RepliesI have the following AS code to draw a single rectangle using mouse, but I need a different code that allows drawing multiple rectangles and the selection/exclusion of individual rectangles like a modeling tool (eg.: MS Visio).
View 2 Replieshow can i duplicate a movie clip and then place it on a certain place on the stage
View 5 RepliesI'm trying to place my mc's at a different position each time the game starts but within a certain area. I've used random before...
random(300);
...but I want it to be randomly between the coords
_x 150 and 450
_y 250 and 350
I've used .x = and .y = with the position I want and the pane continues to show up in the top left corner instead. What am I doing wrong?
View 2 RepliesI'm trying to develope a simple game, but i'm facing a problem, that I think it is simple for yours who have experience in AS3.I trying this:
Quote:
...LOOP.........
var dynamicObj:MovieClip = new MovieClip();
[code].......
I want to attach a mc from the library, then duplicate it 2-3 times, and have the duplicates start in random _x / _y locations on the stage. They then slowly drift across stage.The code I've got so far loads the mc from the library, duplicates it once, and places it randomly. But it only creates one duplicate instead of 2 or 3. And I suspect it could be simplified.So I need corrected code to create 2 or 3 duplicates, and have them start randomly and move at the same speed across stage. Maybe advice on how to allow them to move at different speeds would be useful as well.[code]
View 2 RepliesI am trying to figure out how to randomly place four cards on stage through external AS3, by arrays.For example:
Code:
var positionArray:Array = ["48.50", "125.50", "202.50", "280.50"];
function getXAxis():String
[code]......
I am new to flash programming. I have to create a flash card game for a client.There are 52 cards with back showing in 52 rectangles. Each time the swf loads the position of the cards has to be different (randomly placed) in those 52 rectangles. Click on the card and the face of the card shows. Also an option for shuffle. When the user clicks on shuffle, the cards are randomly placed.
View 1 RepliesIs 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 RepliesIs there a way to add a grid of rectangles together so that you can get a "container" rectangle (the bounds) of all the rectangles put together?
View 1 RepliesI have four dynamic text field created at the authoring time in Frame-4. I just need them to be placed randomly every time when I come from Frame3. I have known that there is a Math Class which generates random numbers which would be an effective way. how do I proceed ahead i.e shall I create an array and seed it with the their current positions etc etc
View 5 Repliesif I have an array like this:[code]then I want to get the order number of the orange, which is 1, out. Is there any way to do that?
View 3 RepliesI'm trying to get a text field that behaves like a fake hit-counter. Adding random numbers and getting larger each time:
My code doesn't add up though, it just replaces the text each time!!
var incrementTimer:Timer = new Timer(1000,0);
var lastNumber:uint = 0;
incrementTimer.addEventListener(TimerEvent.TIMER, incrementNumber);
incrementTimer.start();
[Code]......
I looked everywhere on the internet and couldnt find how to generate a random number that had one decimal place.I am trying to generate numbers between 12.0 and 13.0 randomly.Below is my code... I know its wrong because of Math.round and Math.random, but i cant seem to find anything that deals with a decimal place.
addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler_1);
function fl_EnterFrameHandler_1(event:Event):void{volt.text = Math.round(Math.random()*(1)+12).toString();}
[code].....
i created a movie that gets a certain number of nodes from an xml file and places them randomly on the screen. The only thing is, that it does them at the same time. i want them each to be placed seperatly on the stage, getting faster as the movie progresses.
[Code]...
The counter displays sprites in place of number values. More experienced programmers have given me a clue. Why am I getting error # 1010. Secondly, what am I not seeing that's so obvious? I wish I went in to this with a better foundation in actionscript 3, but I'm reading and doing my best. WHAT I SEE
-dollar sign indicates a variable or array "$numbers"
-import flash.utils.Dictionary; "indicates an associative string"
-Error #1010: A term is undefined and has no properties
-is the associative string is fooling me? "maybe I set no values, duh"
-are the property of my symbols are set wrong?
[Code]...
I've been working on my new flash site for a few weeks, along with learning AS3, tackling problems as I encounter them and I've learned a lot...but sometimes the simplest things I cannot figure out for the life of me.
All I am trying to do is have some flash banner SWF files I created play within the portfolio page of my site. I don't want them to open in a pop up or anything just play within the page when the link on my site is clicked. I figured it would act like a movie clip and I could just drop it onto the stage, but when I do that it doesn't look right, loops continuously, and is not interactive.
Is it possible to place a PDF onto the stage and add it to the display list? Are there plugins out there that can accomplish this?
View 3 RepliesIn this .swf where can I place the stage color? I am using the[url].... and it made the stage color black? Which is suppose to be #999 .HERE IS THE CODE SCRIPT:
<object width="600" height="409"> <param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf"></param><param name="flashvars" value="src=http%3A%2F%2Fgfdesignwise.com%2Fjbm_sit e%2Fvideo%2Fsplash.swf&controlBarMode=none&playBut [code].....
i want that a MC appears randomly on the stage but with the time...like 1 second, and then after 1 second, it randomly appears somewhere else on the stage (800x600).
View 6 RepliesI want to place my duplicates about one third down from the top and in a small bit from the left. Roughly centre them on stage. My code so far:
for (var i = 1; i <= 6; i++){ duplicateMovieClip ("fish_mc", "fish_mc" + i, i); _root["fish_mc" + i]._x = 500 * Math.random (); _root["fish_mc" + i]._y = 350 * Math.random ();}
if i make say a button in my timeline, convert it to a button. and then remove it from the stage (it is still in the library) in my exeternal .as file how can i then place that movieclip on the stage? i know how to do this within the timeline, but not when it is an external .as file.
View 7 RepliesThe player controls the character with their mouse - it follows their cursor. I'm trying to make an environment continually scroll from the right hand side of the screen to the left - much like in Canabalt (click to see). I've been trying to do this with tweens, but it doesn't seem like it's going to be the most efficient way of doing it... Plus Flash keeps dying on me whenever I try to do it.
I have a couple of background images, and then I have objects in the foreground that the player is going to destroy by mousing the character over them. How do I get Actionscript 3 to place instances of movieclips on the screen at certain points, and make them to scroll from the right of the screen to the left? I have a lot of different movieclips to use, so it'd also be great if they could be removed from the stage once they reach a certain point.
if I want to randomly select an image from the stage, by using an array, and send it to the location of a box on stage (ranPair1), how could I do that?
var cardArray = new Array();
cardArray[1] = "twoC, twoH";
cardArray[2] = "threeC, threeH";
[Code].....
im not sure how to about this... i think it may have something to do with the addChild() function
View 3 Replies