Topic: flashvars.firstImageIndex out of range

Hi,

I have problem I coding direct linking to my images (without back-forward browser buttons)

Here is code:

flashvars.firstImageIndex = index;
flashvars.baseURL = "http://xxx/photos"+href+"/";
           
simpleviewer.ready(function () {
     simpleviewer.load('sv-container', '100%', height+"px", "transparent", true, flashvars);
});

index is a variable grabbed from url. I have 20 images in gallery, when the index becomes 21 gallery isn't load. How to correct it and load gallery with flashvars.firstImageIndex = 0

Re: flashvars.firstImageIndex out of range

If all you want to do is ensure that the value used for the firstImageIndex is between 0 and 20 (inclusive), then you could use the following:

flashvars.firstImageIndex = Math.max(0, Math.min(index, 20));
Steven Speirs
SimpleViewer Support Team.

Re: flashvars.firstImageIndex out of range

Oh no....

I'll try to explain it better.

I set up direct linking i.e.

if I point my browser to http://xxx/photos/exmaple#1

simpleviewer starts and show 1st image in ths galley - this is correct

if I point my browser to http://xxx/photos/exmaple#2

simpleviewer starts and show 2nd image in ths galley - this is correct

but

if I point my browser to http://xxx/photos/exmaple#21

simpleviewer don't start because in example gallery I have 20 images
and firstImageIndex is set to 21

I would like in this situation simpleviewer start and show first image,
You never know what user put in address bar :-)

Re: flashvars.firstImageIndex out of range

I do not know how you are extracting the #index from the URL but if, in your first post, the variable 'index' is the number after the # in the URL, then my code should work fine.
Just replace:

flashvars.firstImageIndex = index;

... with:

flashvars.firstImageIndex = Math.max(0, Math.min(index, 20));

The gallery will then use the #index number as the firstImageIndex in the gallery but if the #index is above 20, the gallery will use 20 and if the #index is below zero, the gallery will use 0.

If you continue to experience difficulties, please post the full code that you are using (or post the URL to your gallery) so that I can take a look and help further.

Steven Speirs
SimpleViewer Support Team.

Re: flashvars.firstImageIndex out of range

Thanks for your explanation, I used your code combined with my own, and now everything works correctly, my own part is in php, because I have few galleries, so javascript never know number of photos in desired gallery.

javascript part as you wrote:

variables:
*index  - extracted from url via javascript
*number - from php code (below)

flashvars.firstImageIndex = Math.max(0, Math.min(index, number));

and finally my php code:

$url = $_SERVER['REQUEST_URI'];

$path = parse_url($url, PHP_URL_PATH);

$explodedpath = explode("/", $path);

$xml = simplexml_load_file("http://xxx.xxx/photos/$explodedpath[1]/gallery.xml");

$number = count($xml->image);

echo "\t<script type='text/javascript'>var number = $number</script>\n\n";

Of course this is simplified version, I also have part which checking the url in order to prevent load gallery.xml file from non existant locations.

P.S. I'm using global javascript variable for transfer value from php to javascript, I don't like to use global variables, but it is best I can do (AFAIK)

Re: flashvars.firstImageIndex out of range

I used your code combined with my own, and now everything works correctly

That's great to hear! It certainly looks like your code should work fine.
Alternatively, you should be able to do the following:

flashvars.firstImageIndex = Math.max(0, Math.min(index, <?php echo $number;?>));
Steven Speirs
SimpleViewer Support Team.

Re: flashvars.firstImageIndex out of range

I'll try. Thank you for Your support.

Last edited by YaPKnn (2014-02-02 14:23:30)