Jump to content
Official BF Editor Forums

Flash Menu Randomise Background Problems


rhysm_08
 Share

Recommended Posts

Trying to get the sandbox menu for my mod, and after finding the source files and spending a long time getting the fonts working, i now have a working flash menu for my mod. But, that's not enough :P. I've been working together to try implement a feature that should be do-able. A Randomised background, that changes each time the mod is loaded. With plenty of background images, it should add a nice variety within the mod. The problem, however, is the code.



h = ["Strokes_small.png", "Dirty2_small.png", "Bokeh4_small.png"];
i = 3 //Catches the number of values inside the "h" array
j = Math.floor(Math.random()*i); //A random value, with a ceiling equal to the length of the "h" array
k = h[j] //Defines the path for the background to be used.

this.background_img.loadImg(k)

Now, if i change "this.background_img.loadImg(k)" to the image filename, which is located at the root of the mainmenu, to simplify things, it does actually work, but it only loads 1 image, which defeats the purpose of this code.

Edited by rhysm_08
Link to comment
Share on other sites

Math.Random() doesn't work in BF2 Flash (well it does, but it's not seeded by anything, so it's just the same number pattern over and over, which is probably since it can't get the time). To work around this, I built my own off the "getTimer()" function, which is a timer showing how long flash has been running, which should be different each time it's called, so it should give off a somewhat random number. Something like the following should do the trick (which gets the first decimal point number):

function getRandomIntInRange(bottom:Number, top:Number) {
var dif:Number = top-bottom+1;
var random1:Array = new String(((getTimer()-1000)/1000).toString()).split(".");
var random2:String = new String(random1[1]).charAt(1);
return Math.floor(bottom+(dif*(random2/10)));
}

Then you would just call it like:

var images:Array = ["Strokes_small.png", "Dirty2_small.png", "Bokeh4_small.png"];
this.background_img.loadImg(images[getRandomIntInRange(0, 2)]);

Should work, was a while since I coded it for the random login images in Project Reality, can't remember if that's all I did or if I did something else to make it work...

Edited by AncientMan
Link to comment
Share on other sites

Wow, cheers!<br><br>It loads "Strokes_small.png" for the menu, after login it would occasionally change between "Bokeh4_small.png" and "Dirty2_small.png". I guess your code works, but how would i change this if I had 7 images? How would that affect the code?<div><br></div><div>EDIT: Unrelated problem, but still annoying lol. Everytime I login, even with internet disconnected, it loads a newsticker that says "go to sandbox to download latest version and avoid being disappointed" Now i'm finding it hard to find the line of code that even raises that in flash, but it must be somewhere. If I run the SWF directly it says<br><br>where the ticker is "http://sandboxmod.com/ingame/newsticker .1.0.0.png". Now I find this strange, as the newsticker image is not even in the flash images folder, and if it is loading from online, i wonder how it does that even when i switch off the internet :o</div>

Edited by rhysm_08
Link to comment
Share on other sites

If you want, you can add in 20 or so frames right at the beginning of the timeline with a black sprite over the top. This will slightly increase the time taken to get to the login menu, but it will allow you to have a more random number, since the time will be increased, giving a more likely chance of a slight variation in milliseconds.

As for adding in more images, just add the names into the array and fix up the range so it's from 0 to 6 or however many images you have... You could also do something like:

this.background_img.loadImg(images[getRandomIntInRange(0, images.length - 1)]);

Then you only need to add in new images into the array, and don't have to worry about changing the range.

Link to comment
Share on other sites

Cool, it works with many pictures. As a feature, it changes the background when logging in as well :). Though, having 1 last issue with the news ticker.

Here's an example...

menuglitch.jpg

As you can see here, there is an unwanted newsticker. Getting very frustrating as I can't find the code in flash, just a sprite that is a grey colour.

Also, as stated before, I am using the sandbox menu here: http://sandboxmod.com/forums/viewtopic.php?id=510

Edited by rhysm_08
Link to comment
Share on other sites

BF2 flash can't have external dynamic text (well not natively anyway). It will be an image container with the text being an image. Also, if you haven't realised already, everything is grey boxes :P. The boxes are used for basic positioning, then actionscript takes over and draws it through code. Just delete the image container and you'll be sorted :). Or do a search for the actionscript name of the image container, and it'll show up in the code, since it has to be referenced for it to load the image.

Edited by AncientMan
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...