Expand my Community achievements bar.

passing correct image-file path in flashVar from jsp into embedded Flex application

Avatar

Former Community Member
I have an application that embeds an image viewer, written in
Adobe Flex within a jsp page running in a J2EE application on
Tomcat 5.5. The Flex code is a one-line modification of the
application displayed at (
http://www.adobe.com/devnet/flex/samples/fig_panzoom/).




The image viewer is founded and loaded in the output to the
screen, but I cannot get the Image Viewer to display the image
correctly, even though I succeed when either I run the .swf from
the command-line or from an HTML page.







My webapp is called FRSApp. The directory structure is, under
FRSApp:



myTest.html

jsp/catalog.jsp

pan_zoom_files/images/map.jpg





The JSP code is thus,



code:







<%@ taglib prefix="mm" uri="FlexTagLib" %>

<mm:mxml
source="../pan_zoom_files/FIG_PanZoom_for_jsp.mxml" >

<mm:flashvar name="myVar"
value="/FRSApp/pan_zoom_files/images/map.jpg"/>

</mm:mxml>





the code within PanZoom.mxml is,



private var _imageURL:String =
Application.application.parameters.myVar;

...

<ns1:ImageViewer

id="imageViewer"

imageURL="{ _imageURL }"

bitmapScaleFactorMax="5"

bitmapScaleFactorMin=".05"

width="100%" height="100%"

x="0" y="0"/>



...





I have tried other paths to the image file, including



images/map.jpg [required by command-line execution of .swf]



pan_zoom_files/images/map.jpg [required by HTML page
(myTest.html) that embeds the .swf file]









I have succeeded in loading image viewer embedded in the jsp
page when the image path is hard-coded in the mxml file, by means
of the following code:



<div id="swf-id" class="swfcontent"><embed
type="application/x-shockwave-flash"
src="../pan_zoom_files/FIG_PanZoom_for_jsp.swf" id="swf-id"
name="swf-id" bgcolor="#ffffff" quality="high" wmode="opaque"
height="480" width="772"></div>

<script type="text/javascript">

// <![CDATA[

var props = new Object();

props.swf = "../pan_zoom_files/FIG_PanZoom_for_jsp.swf";

props.id = "swf-id";

props.w = "772";

props.h = "480";

props.ver = "9";

props.wmode= "opaque";

var swfo = new SWFObject( props );

registerSWFObject( swfo, "swf-id" );

// ]]>

</script>





The error is either a "failed to load image" generated by the
Image Viewer code, or a Flex system error message, resembling a
null-pointer exception:





TypeError: Error #1009: Cannot access a property or method of
a null object reference.

at FIG_PanZoom_for_jsp()

at _FIG_PanZoom_for_jsp_mx_managers_SystemManager/create()

at mx.managers::SystemManager/initializeTopLevelWindow()

at mx.managers::SystemManager/docFrameHandler()







Any ideas are greatly appreciated!!
1 Reply

Avatar

Former Community Member
Solved the problem. I had made several mistakes. One of them
was to pass in the J2EE context path when what was needed was the
fully qualified image url:
http://localhost/FRSApp/pan_zoom_files/images/earth-map_small.jpg.
The second mistake was to assume the flashvar variable could be
picked up by initializing Action Script in the the mxml file,
designated by <mx:script> tags. No, the flash variable will
only be visible within the <mx:Application>
</mx:Application> tags.