This content has been marked as final. Show 14 replies
Your positions appear to be evenly spaced on x at 60 pixel intervals. If that's always going to be the case then don't do it in the xml. Its pretty easy to do a random placement from actionscript for that.
No i want random positions of x ,y , its may be 20 or 60 or 43 or 23 anything for a single object and respectively for all , so please help me out for this problem or give me ny solutions
you should get your XML file length. after that you should set a random number between 0 & xml.length. then set your movie to set your object position with xpos and ypos attributes. if you have any question mail me. " firstname.lastname@example.org ". l3ye
Ok.. you should do it from actionscript. You don't need xpos and ypos attributes in the xml.
Can you post your existing code where you are currently "getting the value of an object name , path , X , Y position and set it on the screen" . It will be easier to advise you from your existing code.
And you should think about these aspects/requirements - please give quick answers:
1. Is it important that the random positions selected avoid the images overlapping eachother?
2. What is the width and height of each image... are they the same or do they differ?
3. If the images differ in size do you need to scale them to be the same size on-screen or do they need to be displayed at their original size.?
4.If answer to (1) is yes... what do want to have happen in any potential situation where it might be impossible to find sufficient space to place further images (e.g. list is too long, or image size too big with inefficient layout from true random placement) (This is a problem that might be avoided by using random known locations e.g a grid or table layout - but that's not what you asked for).
Ok fine , what i will do is posting my code u just go through it. and please suggest me. In the code xps is the x position of object and yps is y position of an object.
And the answer of ur first question is that there might be images of different size but we have to scale them in a similar size and then show it on the screen randomly so there should'nt overlaping occured. please review the code how i can get path, name , xpositoon and yoisition from a xml file and then show it on the screen , its loks little static rather i want more dynamic so please suggest me on these topics ASAP , its hectic for me . Please help me out Thanks
can u plesae describe me thorrowly if u can ?? because i have lots of confusion regarding ur answer.
You seem to have understood well the first few points - because you gave answers to them.
To explain more thoroughly my last point...as a concept its quite simple: Imagine your images were exactly sized to fit on the screen in a 2 X 2 grid... so each image was the same size and there were 2 across, 2 down - completely filling your screen. You can now randomly place 4 images in each of the set locations... a grid or table (in this case a 2 x 2 grid). If you did that then they would not overlap and you can fit 4 images on screen. But if I randomly place one image and it doesn't go completely in one of the grid positions... then it will limit the number of images that you can place - you will never be able to place 3 more (without scaling down). After 1 image it might already be impossible to place any more in this example. The same principle applies in a smaller space, with larger numbers of smaller images where you don't constrain to a grid layout - and you don't permit overlapping.
In terms of solving it... well I'm not too sure... I've not had to deal with it myself before. Depending on the number of images, their size and the space have to put them in... sometimes it might be OK and other times not.
If you want all the images to be displayed then (I think) you need to make sure the size of the images is such that you will always be able to place the number you want even with the most inefficient placement possible (even if its not very probable from random placement). In the example of a 2 by 2 grid I believe the most inefficient placement of one image would be in the centre. But by using this as a reference and reducing the size of the image until you get to a size where others can be placed around it then you should be able to fit 4 on-screen again with random placement. I'm not an expert at this stuff (not at all). I guess I'm trying to understand it a little better myself...and probably over-complicating it in the process. I've always done random placement to grid locations in the past. Anyhow perhaps others can advise whether some extension of this approach can be used to determine image size for a given number of images and a given space to allow true random placement of all the images under all circumstances.
Also looking at your code I see what you mean about it being static and understand why you want to change it.
You should make more use of loops and dynamic naming of the clips you load into.
I also suggest using the MovieClipLoader class and the onLoadInit handler for each clip. This will be the best place/time to resize the images if they are different sizes as you say.
I would like to be more specific, but I think you need to start with that and get things working that way first. And in terms of the random placement - assuming you have a number and size of images that will always fit in the space when allocated randomly... then I can think of the easy way (which is not very efficient and could get stuck working on placement for some time if the spacing was tight)
a. choose random x and y coords and check if it is occupied (e.g. hitTest all previously loaded images). If yes go back to start of (a) .
b. check the random x coord+image width, y+ image height... is it occupied (same again) ? if yes go back to (a)
c. place image there.
To do it more efficiently perhaps someone else has some existing code to track placements and limit the selection of the random points to the space that is not currently occupied.
that means i have to devide my stage in grids and then place objects according to avaibility of positions right?
dont u think it makes heavy line of codes??? any other way we can optimize things ???
No I wasn't saying you had to place in a grid... I was just saying that's a lot easier (and for me at least - more familiar). What is the size of the images (width x height ) -after they've been resized if necessary - and the size of the space (width x height ) that you'll be placing them in?
And what is the maximum number of these images you need on screen?
its might be above than 20 and the size of the images width=80 and height=120 .
i am trying to fix this problem and mya be done by today eve but now i has a problem regarding attahing these movieclips(images) to a label (movieclip) on the stage and when i will move label the all images shoild move with label which attched to that label , i have tried lot through hit test but not working because i have lots of dynamic movieclips(images) and how to attach these movieclips on the label movieclip which is static movieclip in my case do u have any sample or any question regarding this ??? pl help me out .
Ok... so 20 or more images... each image is 80x120.
What is the width and height of the space you want to put them in?
Re your last post... have you already solved this problem for random placement? If so... then I suggest you request help on the separae issue in a separate thread - or continue with it in one if you have already started a topic for that. It makes sense for many reasons.
ok fine i haveallready posted it in a new thread