Topic: Embedding in Flash CS4

Hi,

I'm new to using Flash. I'm using Flash CS4. I wanted to embed simpleviewer pro within this flash template - http://www.flashvillage.com/forums/showthread.php?t=134. The idea was that the various tabs on the side would lead to different simpleviewer galleries. A preview of the template can be seen here - http://www.flashvillage.com/templates/Crisp/index.html.

My problem is that I can't seem to work out how to embed a swf file within a fla file. The support page says:

The following code shows how to load SimpleViewer into a shell movie:

var svLoader:Loader = new Loader();
addChild(svLoader);
svLoader.contentLoaderInfo.addEventListener(Event.INIT, onViewerInit);
svLoader.load(new URLRequest("simpleviewer.swf"));

/**
* Fired when preloader is available
* Can set gallery flashvars at this point
*/
function onViewerInit(e:Event):void{
Object(svLoader.content).addEventListener("SV_COMPLETE", onGalleryLoaded);
var options:Object = Object(svLoader.content).embedOptions;
options.galleryURL = "my_gallery.xml";   
}   

/**
* Fired when gallery has completely loaded. API is now available.
*/
function onGalleryLoaded(e:Event):void{
svAPI = Object(svLoader.content).api;
svAPI.setSize(640,480);
}

I'm not sure what a 'shell movie' is. I tried putting the code within Layer 1, it didn't help.

Is there any chance you could provide a series of very simple steps from scratch that would show me how to embed a simpleviewer swf file within a fla file? If you could download that template and show me how to replace one of the numbered fla files (e.g. 2.fla) with a simpleviewer file, that would be extra helpful...

Many thanks,

Alan

Re: Embedding in Flash CS4

Have you taken a look at the example that comes with the pro download?

Mike Richards
SimpleViewer Support Team.

Re: Embedding in Flash CS4

Yes, I looked at them, it didn't help.  sad

I couldn't work out how to use the examples in another site.

Also, is there any way I could get hold of the fla files of simpleviewer pro? I thought it would come with the swf files when I bought it...

Re: Embedding in Flash CS4

Hi,

is that template ActionScript 3? Embedding SimpleViewer requires the embedding movie to be ActionScript 3 and requires Adobe Flash CS3 (or later) authoring software.

Does SimpleViewer-Pro include the Flash Source Code?

No. All config options are now configurable via XML. Flash developers who want complete control over the look and feel of the gallery can embed SimpleViewer-Pro into a Flash movie and use the ActionScript API to create a completely custom user interface.

Felix Turner
SimpleViewer Support Team.

Re: Embedding in Flash CS4

Yes, it is ActionScript 3.0. And about which version of Flash, as I said, I'm using Flash CS4.

Back to the original question, could you provide very simple steps from scratch that would show me how to embed a simpleviewer swf file within a fla file? Basically a tutorial of how you made the example. (I don't need the controls on the left side as much, just embedding the simpleviewer would be enough).

I've been struggling with this for several days...

Thanks again,

Alan

Last edited by alana (2010-02-18 23:12:13)

Re: Embedding in Flash CS4

I just checked that template, it is AS1 so that is the problem.

As far as example code showing how to load SimpleViewer, the example code and FLA are here: http://www.simpleviewer.net/simpleviewe … html#flash

Felix Turner
SimpleViewer Support Team.

Re: Embedding in Flash CS4

I tried to do it with a new Flash File (ActionScript 3.0) just to get the idea, and I still don't get it.

I'm not sure what to do. Should I create a new layer? Should I insert a new symbol (via Control-F8)? The template has a loader, am I supposed to add a loader? The code I quoted before - do I just stick it in (editing the file names appropriately) or is there something I should do?

To summarise, I want to be able to replicate what you've done with the example, and whatever I do, it doesn't seem to work... Could you supply simple steps for embedding (e.g. 1. create a new layer. 2. Insert symbol and label it...). That way I can isolate what I am doing wrong.

Thanks!

Alan

Re: Embedding in Flash CS4

To replicate the example without the extra API code do the following.

In a new AS3 FLA set the stage size to 800 by 600

Create 3 empty movie clips in your library called frame, loader and button in your library.

Double clip to open the frame movie clip.

Draw a rectangle 650 by 500 and align it top left.

Double clip to open the loader movie clip.

Drag the frame movie clip into loader from the library and align it top left

Give it an instance name of mcFrame

Double clip to open the button movie clip.

Add an appropriate sized rectangle to the button clip.

Go back to scene 1

Add a layer called sv_loader drag the loader symbol to the stage into the sv_loader layer and give it an instace name of mcLoader. This is what the SimpleViewer gallery will load into.

Add a layer called buttons drag the button symbol to the stage twice into the buttons layer and give one an instance name of mcButton1 and the other call mcButton2.

Use the text tool to add a label to the buttons.

Add a layer called actions and in the actions tab for that layer add the following code.

/**
 * SIMPLEVIEWER FLASH EMBED 
 *
 * This example shows switching between 2 galleries with different gallery xml files 
 *
 * 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);
    
}

//Init Button Click Handlers
mcButton1.addEventListener(MouseEvent.CLICK,loadGallery1);
mcButton2.addEventListener(MouseEvent.CLICK,loadGallery2);


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

function loadGallery2(e:Event){
    loadGallery("gallery_2.xml");
}
Mike Richards
SimpleViewer Support Team.

Re: Embedding in Flash CS4

I have been having trouble with this as well, as I am new to flash.
I learned to make my website by using tutorials through lynda.com  which have been excellent

however, I am sorry to say that without those guidelines, I am not too sure where to put what and how... basically

I tried the steps posted on this forum with no success.

I really would appreciate some step by step help in how to get multiple galleries on one page of my flash site. I can include a screen shot of the site if necessary so you can see the layout I am looking for.

I am very frustrated with the directions given thus far and I really do not wish to return the product for a refund. The product is great, the directions on using it... not so much... unless you are a pro in flash or dreamweaver... of which I am neither.