![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
I need a little assistance correctly loading an external swf file into my flex
application. I'm not sure where I've gone wrong, but at this point I'm assuming that it's a path error of some sort. The swf file that I'm trying to load is actually a http://soundslides.com/ presentation which was built using AS2 and relies on a flashvar called "project" to feed it the necessary xml document. The flex application is being inserted dynamically into the page using a Jquery plugin. Here's a live version of what I'm trying to accomplish. It was built using Jquery and Soundslides, but due to some unforeseen browser complications I've decided to rebuilt the entire widget using Flex instead of Jquery. Example 1: Original version using Jquery + Soundslides - Look at the sliding student views section. http://www.plu.edu/admission/first-year Example 2: Flex + Soundslides - This is a work in progress, and it's the version that I need help with. http://dev.plu.edu/admission/home-sv-widget.php So basically in example 2 I've got a sequence of jpgs that are set to slide forward at a given time interval. When a user clicks on one of the jpgs the mouse event calls the following method: Code:
// Load Soundslide
public function loadSoundslide (e:MouseEvent):void
{
// Get project id from button id
var projID:int = currentImage;
// Create path for loader
var swfPath:String = basePath + playerPath + "?project=" +
basePath + projectsArray[projID];
//Alert.show(swfPath);
// Load Soundslide swf
swfRequest.url = swfPath;
swfLoader.load(swfRequest);
wrapper.addChild(swfLoader);
}
thoughts? One more question. Say I get this to work. Would I just call another method for unloading the swf? Attached is my project so that you have a sense of what I'm working on. I'm also going to post a zipfile]http://dev.plu.edu/admission/admission-studentviews.zip containing more of the project, the student-views content is rather large so I'm only going to include one of them. <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundAlpha="0" horizontalScrollPolicy="off" creationComplete="init();" width="380" height="264"> <mx:Style source="sv.css" /> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.controls.Button; import mx.controls.Image; import mx.effects.Move; // XML public var xml:XML; // Image Mask [Bindable] [Embed(source="assets/images/mask-sv.png")] private var maskPng:Class; // Image variables [Bindable] public var currentImage:int = 1; [Bindable] public var nextImage:int; [Bindable] public var prevImage:int = 1; // Project variables public var projectsArray:Array = new Array(); // Base path public var basePath:String; // Playback options public var playerPath:String; public var slideDuration:int; // Swf Loader public var swfRequest:URLRequest = new URLRequest(); public var swfLoader:Loader = new Loader(); // Misc public var interval:uint; [Bindable] public var alertDump:String; // Intialize public function init():void { // Setup XML var xmlDefault:String = "assets/student-views/home.xml"; var xmlPath:String = Application.application.parameters.xmlpath; if(xmlPath != null) { xmlDefault = xmlPath; } var loader:URLLoader = new URLLoader(new URLRequest(xmlDefault)); loader.addEventListener(Event.COMPLETE, onLoaded); } // XML has been loaded public function onLoaded (e:Event):void { // Assign the XML data to a variable xml = new XML(e.target.data); // Setup options basePath = xml.setup.site.basePath; playerPath = xml.setup.playback.playerPath; slideDuration = xml.setup.playback.slideDuration; // Create images/buttons var idCount:uint = 1; for each (var property:XML in xml.items.item) { // Build imageStack item // Setup image var imageItem:Image = new Image(); imageItem.id = "img" + idCount; imageItem.source = property.image; imageItem.setActualSize(380, 240); imageItem.useHandCursor = true; imageItem.buttonMode = true; imageItem.addEventListener(MouseEvent.CLICK, stopInterval); imageItem.addEventListener(MouseEvent.CLICK, loadSoundslide); // Add image to imageStack (HBOX) imageStack.addChild(imageItem); // Build button item // Setup button var buttonItem:Button = new Button(); buttonItem.id = "btn" + idCount; buttonItem.name = "btn" + idCount; buttonItem.label = idCount.toString(); buttonItem.width = 20; buttonItem.height = 20; buttonItem.useHandCursor = true; buttonItem.buttonMode = true; buttonItem.addEventListener(MouseEvent.CLICK, stopInterval); buttonItem.addEventListener(MouseEvent.CLICK, moveHorizontalBoxMouse); // Add button to vbox buttonSet.addChild(buttonItem); // Build Project Array projectsArray[idCount] = property.project; // Increment variables idCount++; } // Update button state updateButton(); // Start imageStack loop interval = setInterval(advancePlayer, slideDuration); } // Advance player public function advancePlayer ():void { if(currentImage <= imageStack.numChildren -1) { nextImage = currentImage + 1; } else { nextImage = 1; } // Move imageStack moveHorizontalBox(nextImage); } // Stop interval public function stopInterval (e:MouseEvent):void { clearInterval(interval); } // Update button public function updateButton ():void { // Set previoius button state to out Button(buttonSet.getChildByName("btn" + prevImage)).dispatchEvent(new MouseEvent(MouseEvent.ROLL_OUT)); // Match button state to current image Button(buttonSet.getChildByName("btn" + currentImage)).dispatchEvent(new MouseEvent(MouseEvent.ROLL_OVER)); } // Move Horizontal Box (Mouse) public function moveHorizontalBoxMouse (e:MouseEvent):void { var imgID:int = int(e.target.id.substr(3,1)); moveHorizontalBox (imgID); } // Move Horizontal Box public function moveHorizontalBox (id:int):void { // Determine x var x:int = (id - 1) * 380 * -1; // Move imageStack to x position var move:Move = new Move(); move.end(); move.xTo = x; move.duration = 2000; move.target = imageStack; move.play(); // Update previous image prevImage = currentImage; // Update current image currentImage = id; // Update button updateButton(); } // Load Soundslide public function loadSoundslide (e:MouseEvent):void { // Get project id from button id var projID:int = currentImage; // Create path for loader var swfPath:String = basePath + playerPath + "?project=" + basePath + projectsArray[projID]; //Alert.show(swfPath); // Load Soundslide swf swfRequest.url = swfPath; swfLoader.load(swfRequest); wrapper.addChild(swfLoader); } ]]> </mx:Script> <!-- Begin Wrapper --> <mx:Canvas id="wrapper" height="264" width="380" cacheAsBitmap="true" mask="{imageMask}" horizontalScrollPolicy="off"> <!-- Begin Image Stack --> <mx:HBox id="imageStack" height="240" horizontalGap="0" horizontalScrollPolicy="off" > </mx:HBox> <!-- End Image Stack --> <!-- Test Labels --> <!-- <mx:Label text="Current Image + {currentImage}" y="10" /> <mx:Label text="Next Image + {nextImage}" y="25" /> <mx:Label text="Previous Image + {prevImage}" y="40" /> <mx:Label text="Alert Dump + {alertDump}" y="55" /> --> <!-- Test Labels --> <!-- Begin Navigation --> <mx:Canvas id="navigation" styleName="navigation" width="380" height="24" x="0" y="240"> <!-- Begin Label --> <mx:Label text="Student Views" x="12" y="4" /> <!-- End Label --> <!-- Begin Button Set --> <mx:HBox id="buttonSet" styleName="button-set" horizontalGap="2" horizontalAlign="center" width="380" height="21" x="0" y="3"> </mx:HBox> <!-- End Button Set --> </mx:Canvas> <!-- End Navigation --> </mx:Canvas> <!-- End Wrapper --> <!-- Begin Image Mask --> <mx:Image id="imageMask" source="{maskPng}" cacheAsBitmap="true" width="380" height="264" /> <!-- End Image Mask--> </mx:Application> |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise