Topic: load simpleviewer galleries into flash scene

Hi there,

i just purchased svBuilder-Pro 2.1.2 and i have a question on not using iframes.

I am working on a main flash site which loads external .swf files and various data, and a want to load different galleries built with svbuilder into the flash scene. like that of, multiple gallery buttons in a flash scene, each calling different galleries into the main flash files. i do not want to use the iframe method, because the main flash scene has animations on the background and i need to place the galleries into a containe movieclip (whse alignments are controlled with stage.align  codes and such).

any immediate response would be appreciated...

Re: load simpleviewer galleries into flash scene

Take a look at the example included with the pro download examples\flash_embed, you can also find some information on embedding SimpleViewer into flash here.

Mike Richards
SimpleViewer Support Team.

Re: load simpleviewer galleries into flash scene

hi there,
thanks for the quick reply, i examined the file and kind of figured it out...

but i can not find the .fla file for the "simpleviewer.swf". is it not included in the .zip i purchased? as i read through the "simpleviewer_flash_embed.fla" it calls this .swf but we can not modify that .swf?

Re: load simpleviewer galleries into flash scene

The pro version does not include the simpleviewer.fla (source), what are you trying to do that you are thinking you need the simpleviewer.fla?

Mike Richards
SimpleViewer Support Team.

Re: load simpleviewer galleries into flash scene

ok here's the thing.

when i remove all the exceptional buttons other than "load gallery 1", "load gallery 2" (like "show next image", "get gallery info" and such) i get compiler errors on their codes.

and i commented out these lines

/*
mcButton3.addEventListener(MouseEvent.CLICK,showNextImage);
mcButton4.addEventListener(MouseEvent.CLICK,showPreviousImage);
mcButton5.addEventListener(MouseEvent.CLICK,showImage);
mcButton6.addEventListener(MouseEvent.CLICK,getImageIndex);
mcButton7.addEventListener(MouseEvent.CLICK,getImageInfo);
mcButton8.addEventListener(MouseEvent.CLICK,getGalleryInfo);
mcButton9.addEventListener(MouseEvent.CLICK,toggleAutoPlay);
mcButton11.addEventListener(MouseEvent.CLICK,toggleFullscreen);
mcButton12.addEventListener(MouseEvent.CLICK,downloadImage);
mcButton13.addEventListener(MouseEvent.CLICK,openImageLinkURL);
mcButton14.addEventListener(MouseEvent.CLICK,showGallery);
mcButton15.addEventListener(MouseEvent.CLICK,showThumbPage);
mcButton16.addEventListener(MouseEvent.CLICK,getThumbPageIndex);
*/


____

also these funcitons

/*function showNextImage(e:Event){
    svAPI.showNextImage();
}

function showPreviousImage(e:Event){
    svAPI.showPreviousImage();
}

function showImage(e:Event){
    svAPI.showImage(txtImageIndex.text);
}

function getImageIndex(e:Event){
    txtOut.text = "Current Image Index: " + svAPI.getImageIndex();
}

function getImageInfo(e:Event){
   
    var imageInfo:Object = svAPI.getImageInfo(svAPI.getImageIndex());
    txtOut.text = "Current Image Info" +
          "\nimageURL: "  + imageInfo.imageURL +
          "\nthumbURL: "  + imageInfo.thumbURL +
          "\ncaption: "  + imageInfo.caption +
          "\nlinkURL: "  + imageInfo.linkURL +
          "\nlinkTarget: "  + imageInfo.linkTarget;
}


function getGalleryInfo(e:Event){
   
    var galleryInfo:Object = svAPI.getGalleryInfo();
    txtOut.text = "Current Gallery Info" +
          "\nimageCount: "  + galleryInfo.imageCount +
          "\nthumbPageCount: "  + galleryInfo.thumbPageCount +
          "\nthumbPageSize: "  + galleryInfo.thumbPageSize;
}

function toggleAutoPlay(e:Event){
    svAPI.toggleAutoPlay();
}

function toggleFullscreen(e:Event){
    svAPI.toggleFullscreen();
}

function downloadImage(e:Event){
    //Note image downloading only works when SWF is running from a web server
    svAPI.downloadImage();
}

function openImageLinkURL(e:Event){
    svAPI.openImageLinkURL();
}

function showGallery(e:Event){
    galleryShowing = !galleryShowing;
    svAPI.show(galleryShowing);
}

function showThumbPage(e:Event){
    svAPI.showThumbPage(txtPageIndex.text);
}

function getThumbPageIndex(e:Event){
    txtOut.text = "Current Thumb Page Index: " + svAPI.getThumbPageIndex();
}
*/
___________________

now the other two buttons won't call the galleries at all.

i asked for the swf, because i thought it was coming out of an .fls file as well, that i realised it is auto-built with builder, i don't ask for it, yet i examined the package dcontents and i can configur somehow other interface elements, like the arrows and such)

what to do?

Re: load simpleviewer galleries into flash scene

when i remove all the exceptional buttons other than "load gallery 1", "load gallery 2" (like "show next image", "get gallery info" and such) i get compiler errors on their codes.
...
now the other two buttons won't call the galleries at all.

Sounds like something else must have changed beyond what you posted above.

yet i examined the package dcontents and i can configur somehow other interface elements, like the arrows and such

You can create custom arrows by turning the arrows off and using the API to create your own arrows.

Mike Richards
SimpleViewer Support Team.

Re: load simpleviewer galleries into flash scene

well real glad for your responses smile

should i paste the entire code of the flash i am working on here? since it is a paid off thing, it might not be true to share?

i have some aligner and bgstretcher code in the firs lines ( pasted below) the first function is an "aligner", and the other is a bgscaler,


stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

this.stage.addEventListener(Event.RESIZE, hizalaHandler);
this.stage.addEventListener(Event.RESIZE, resizeHandler);

function hizalaHandler(event:Event):void
{
    alignment();
}

alignment();

function alignment()
{

    headmc.y = (stage.stageHeight - headmc.height) - 150;

}


function resizeHandler(event:Event):void
{
    setBackground();
}

setBackground();

function setBackground()
{
    var middleX = stage.stageWidth / 2;
    var middleY = stage.stageHeight / 2;

    bgmc.x = middleX;
    bgmc.y = middleY;

    bgmc.width = stage.stageWidth;
    bgmc.height = stage.stageHeight;

    if (bgmc.scaleX > bgmc.scaleY)
    {
        bgmc.scaleY = bgmc.scaleX;
    }
    else
    {
        bgmc.scaleX = bgmc.scaleY;
    }
}





these are ignorable, but the commented out ones give errors such as:
"Access of undefined property txtOut"

if i comment out the txtOut lines of the code, the funcitons and etc i mean, i get newer errors, all based on the API thing as far as i figured out...

please help me out on this one, i am not good at coding at all...

Last edited by braininpain (2011-02-27 16:52:04)

Re: load simpleviewer galleries into flash scene

when i remove all the exceptional buttons other than "load gallery 1", "load gallery 2" (like "show next image", "get gallery info" and such) i get compiler errors on their codes.
...
now the other two buttons won't call the galleries at all.

Sounds like something else must have changed beyond what you posted above.

ok here's the thing.

i opened the naive "simpleviewer_flas_embed.fla" file, cut "load gallery1" button mc with text and pasted into a new frame, and guided out the original "buttons" frame.
http://img27.imageshack.us/i/layers00.png/

i get a list of errors as in the example
http://img29.imageshack.us/i/errorspi.png/

as of this file, the button does not work as well. either i erase the guide layer, it simply won't work. no commented out actions as well.

the native file has some problems maybe?

still waiting for your reply.

thanks in advance...

Re: load simpleviewer galleries into flash scene

The simpleviewer_flas_embed.fla works fine, it probably is just that there is either a piece missing or some of your code is conflicting with it. I would suggest making a copy of the simpleviewer_flas_embed.fla, start by slowly only removing one piece at a time and running it so that you know there is not an issue with the change you made.

Mike Richards
SimpleViewer Support Team.

Re: load simpleviewer galleries into flash scene

Mike Richards wrote:

The simpleviewer_flas_embed.fla works fine, it probably is just that there is either a piece missing or some of your code is conflicting with it. I would suggest making a copy of the simpleviewer_flas_embed.fla, start by slowly only removing one piece at a time and running it so that you know there is not an issue with the change you made.

hi back again,

i did like you said, but the problem stands still. the .fla file works smooth, only if something is not removed, whenever i try to remove either one of the button mc actions, i get an error message.

if you examined the screenshots i sent you, those are the native file workarounds i sent and like i said, i am not a master in coding, so i am right now questioning the reliability of the original file which i paid for.

waiting for your reply smile

Re: load simpleviewer galleries into flash scene

Are you removing the buttons on the stage as you remove code pieces? Is the project you are trying to integrate the code with using ActionScript 3?

i am not a master in coding, so i am right now questioning the reliability of the original file which i paid for.

There is nothing wrong with the file, here is a copy with the other elements removed.

Mike Richards
SimpleViewer Support Team.

Re: load simpleviewer galleries into flash scene

seems it is not the "removing" problem but, commenting out is not working for the actions on this specific .fla file.


please enlighten me about commenting out, when you remove specific graphical elements on a flash scene, and comment out the actions pointed to them ( via /* ... */ beginning and ending on the code) aren't they supposed to "not look for the graphical elements"?

must i erase them from the code?

far to my wisdom and knowledge on "coding" ( either on html or on css, limited may be but adequate)  they are "unread and ignored" by the application.

should i better send you the .fla file?

Re: load simpleviewer galleries into flash scene

Maybe you missed a line or commented out something you needed. If you only want to comment it out it should look like this.

/**
 * SIMPLEVIEWER FLASH EMBED / ACTIONSCRIPT API EXAMPLE CODE
 * 
 * For API documentation visit: www.airtightinteractive.com/simpleviewer-pro/support/api.html
 *
 * This example shows switching between 2 galleries with different gallery xml files, 
 * and using the API to control and receive events form the gallery.
 *
 * The simpleviewer.swf is loaded into the loader svLoader. 
 * svLoader is a child of the mcLoader stage MovieClip.
 * To move SimpleViewer, move the mcLoader clip.
 * Do not scale the MC that contains SimpleViewer or SimpleViewer will be scaled also. 
 * On loading, SimpleViewer will automatically scale to fit it's parent clip,
 * after that you need to resize it manually using svAPI.setSize(width,height).
 *
 **/

//import required classes
import flash.display.*;
import flash.net.URLRequest; 

//turn off stage auto resizing
//SimpleViewer requires these settings to function correctly
//scaling is handled via the onResize handler (see bottom of this code)
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;        

//Init variables
var svAPI:Object; //svAPI is the object to call API methods on
var swfLoaded:Boolean = false;
var galleryURL:String; //used when switching between galleries
var svLoader:Loader = new Loader(); //loader to load SimpleViewer swf into
var galleryShowing:Boolean = true;

//add svLoader to the "mcLoader" stage movieclip on the main timeline
mcLoader.addChild(svLoader);
//listen for SWF loaded
svLoader.contentLoaderInfo.addEventListener(Event.INIT, onViewerInit);
//load 1st gallery
loadGallery("gallery_1.xml");

/**
* This function loads the SimpleViewer SWF
*/
function loadGallery(url:String){
    
    galleryURL = url;
    
    //unload previous simpleviewer instance
    if (svAPI != null ) svAPI.dispose();
    svAPI = null;
    //flash 9 - unload
    if (swfLoaded) svLoader.unload();
    //Flash 10 - unloadAndStop 
    //if (_viewerLoaded) svLoader.unloadAndStop();
            
    //load simpleviewer swf
    var urlReq:URLRequest = new URLRequest("simpleviewer.swf");
    svLoader.load(urlReq);
    swfLoaded = true;
}


/**
* Fired when preloader is available
* Can set flashvars at this point
*/ 
function onViewerInit(e:Event):void{
    trace("onViewerInit");
    
    //listen for
    Object(svLoader.content).addEventListener("svComplete", onGalleryLoaded); 
    
    trace("setViewerFlashVars");
    var options:Object = Object(svLoader.content).embedOptions;
     //set gallery.xml url based on current galleryId
    options.galleryURL = galleryURL;    
    
}
        
        
/**
 * Fired when gallery has completly loaded (SWF +  XML)
 * API is now available.
 */ 
function onGalleryLoaded(e:Event):void{
    
    svAPI = Object(svLoader.content).api;
    svAPI.setSize(mcLoader.mcFrame.width,mcLoader.mcFrame.height);
    //svAPI.setSize(550,500);

    //txtOut.text = "Gallery Loaded. API now available.";
    
    //Init Event Listeners
    //svAPI.addEventListener("svImageChange",onImageChange);
    //svAPI.addEventListener("svPageChange",onThumbPageChange);
    
    
}

/**
* Called when user views an image
*
function onImageChange(e:Object){
    txtOut.text = "Got Image Change Event: " + e.data;
}

**
* Called when user navigates to a new thumb page
*
function onThumbPageChange(e:Object){
    txtOut.text = "Got Thumb Page Change Event: " + e.data;
}*/

//example resizing code
stage.addEventListener(Event.RESIZE,onResize);
onResize(null);

//called on stage resize
function onResize(e:Event){    
    //strecth bkgnd to match stage dimensions
    mcBkgnd.width = stage.stageWidth;
    mcBkgnd.height = stage.stageHeight;
    
    //resize mcFrame insude mcLoader
    mcLoader.mcFrame.width = stage.stageWidth - mcLoader.x - 20;
    mcLoader.mcFrame.height = stage.stageHeight - mcLoader.y - 20;
    
    //resize SV to match frame size
    if (svAPI != null ) svAPI.setSize(mcLoader.mcFrame.width,mcLoader.mcFrame.height);
    
}

//Init Button Click Handlers
mcButton1.addEventListener(MouseEvent.CLICK,loadGallery1);
mcButton2.addEventListener(MouseEvent.CLICK,loadGallery2);
/*
mcButton3.addEventListener(MouseEvent.CLICK,showNextImage);
mcButton4.addEventListener(MouseEvent.CLICK,showPreviousImage);
mcButton5.addEventListener(MouseEvent.CLICK,showImage);
mcButton6.addEventListener(MouseEvent.CLICK,getImageIndex);
mcButton7.addEventListener(MouseEvent.CLICK,getImageInfo);
mcButton8.addEventListener(MouseEvent.CLICK,getGalleryInfo);
mcButton9.addEventListener(MouseEvent.CLICK,toggleAutoPlay);
mcButton11.addEventListener(MouseEvent.CLICK,toggleFullscreen);
mcButton12.addEventListener(MouseEvent.CLICK,downloadImage);
mcButton13.addEventListener(MouseEvent.CLICK,openImageLinkURL);
mcButton14.addEventListener(MouseEvent.CLICK,showGallery);
mcButton15.addEventListener(MouseEvent.CLICK,showThumbPage);
mcButton16.addEventListener(MouseEvent.CLICK,getThumbPageIndex);
*/

//Button Click Handlers
function loadGallery1(e:Event){
    loadGallery("gallery_1.xml");
}

function loadGallery2(e:Event){
    loadGallery("gallery_2.xml");
}
/*    
function showNextImage(e:Event){
    svAPI.showNextImage();
}

function showPreviousImage(e:Event){
    svAPI.showPreviousImage();
}

function showImage(e:Event){
    svAPI.showImage(txtImageIndex.text);
}

function getImageIndex(e:Event){
    txtOut.text = "Current Image Index: " + svAPI.getImageIndex();
}

function getImageInfo(e:Event){
    
    var imageInfo:Object = svAPI.getImageInfo(svAPI.getImageIndex());
    txtOut.text = "Current Image Info" + 
          "\nimageURL: "  + imageInfo.imageURL +
          "\nthumbURL: "  + imageInfo.thumbURL +
          "\ncaption: "  + imageInfo.caption +
          "\nlinkURL: "  + imageInfo.linkURL +
          "\nlinkTarget: "  + imageInfo.linkTarget;
}


function getGalleryInfo(e:Event){
    
    var galleryInfo:Object = svAPI.getGalleryInfo();
    txtOut.text = "Current Gallery Info" + 
          "\nimageCount: "  + galleryInfo.imageCount +
          "\nthumbPageCount: "  + galleryInfo.thumbPageCount +
          "\nthumbPageSize: "  + galleryInfo.thumbPageSize;
}

function toggleAutoPlay(e:Event){
    svAPI.toggleAutoPlay();
}

function toggleFullscreen(e:Event){
    svAPI.toggleFullscreen();
}

function downloadImage(e:Event){
    //Note image downloading only works when SWF is running from a web server
    svAPI.downloadImage();
}

function openImageLinkURL(e:Event){
    svAPI.openImageLinkURL();
}

function showGallery(e:Event){
    galleryShowing = !galleryShowing;
    svAPI.show(galleryShowing);
}

function showThumbPage(e:Event){
    svAPI.showThumbPage(txtPageIndex.text);
}

function getThumbPageIndex(e:Event){
    txtOut.text = "Current Thumb Page Index: " + svAPI.getThumbPageIndex();
}

*/
Mike Richards
SimpleViewer Support Team.