-
Cross Domain XML not loading
Hello All
I created an XML gallery in as3 that will be loading images from a different domain.
I have a .swf (swf1) on serverA that loads an XML from serverB. The XML on serverB points to the image locations located on serverB (I need to host the images on serverB because server A doesn't have enough room).
The images load fine from swf1 locally in Flash, but when I publish swf1 to serverA, the images do not load. My guess is that the XML on serverB is not being loaded correctly because I can see that swf1 on the webpage.
Does anyone have any idea where to go from here?
Here is how my XML is set up:
<?xml version="1.0" encoding="UTF-8" ?>
<images>
<image src="http://serverB/media/images/image.jpg" title="This is image 1"/>
</images>
Here is my code:
// Create a shuffled image gallery
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.Strong;
import flash.text.Font;
var xml:XML;
var images:Array = new Array();
var imagesLoaded:int = 0;
var imagesTitle:Array = new Array();
var tween:Tween;
var zoomed:Boolean = false;
var canClick:Boolean = true;
var lastX:int;
var lastY:int;
var lastscaleX:int;
var lastscaleY:int;
var nrColumns:uint=5;
var textformat:TextFormat = new TextFormat();
textformat.color = 0xFFFFFF;
textformat.size = 12;
textformat.font = "Myriad Pro";
textformat.align = "center";
textformat.leftMargin= 10;
textformat.rightMargin = 10;
textformat.letterSpacing = 0;
textformat.leading = 10;
// Black Screen
var screen:Sprite = new Sprite();
screen.graphics.beginFill(0x4D7854, .75);
screen.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
screen.graphics.endFill();
function loadXML(file:String):void
{
var urlLoader:URLLoader = new URLLoader();
var urlReq:URLRequest = new URLRequest(file);
urlLoader.load(urlReq);
urlLoader.addEventListener(Event.COMPLETE, handleXML);
}
function handleXML(e:Event):void
{
xml = new XML(e.target.data);
for(var i:int = 0; i < xml.children().length(); i++)
{
var loader:Loader = new Loader();
loader.load(new URLRequest(String(xml.children()[i].@src)));
images.push(loader);
imagesTitle.push(xml.children()[i].@title);
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loaded);
}
}
loadXML("http://serverB/media/xml/images.xml");
//loadXML("xml/images.xml");
function loaded(e:Event):void
{
imagesLoaded++;
if(xml.children().length() == imagesLoaded)
{
prepImages();
}
}
var dictictionary = new Dictionary();
var infoArea:Sprite;
function prepImages():void
{
for(var i:int = 0; i < images.length; i++)
{
var container:Sprite = new Sprite();
var frame:Sprite = new Sprite();
frame.graphics.beginFill(0xFFFFFF);
frame.graphics.drawRect(0, 0, images[i].width, images[i].height);
frame.graphics.endFill();
dict[container]=imagesTitle[i];
container.addChild(frame);
container.addChild(images[i]);
// Resize
if (container.width > container.height){
container.width = 130;
container.scaleY = container.scaleX;
} else if (container.height>=container.width-10 && container.height<=container.width){
container.height = 95;
container.scaleX = container.scaleY;
} else if(container.height>container.width){
container.height = 95;
container.scaleX = container.scaleY
} else if(container.height == container.width){
container.height = 95;
container.scaleX = container.scaleY
}
// Position on Grid
if (i<6){
container.y = 8;
container.x = (i*130)+(i*8) + 8;
} else if (i>=6 && i<12){
container.y = 116;
container.x = ((i-6)*130)+(((i-6)*8)+8);
} else if (i>=12 && i<18){
container.y = 224;
container.x = ((i-12)*130)+((i-12)*8+8);
}
///* Filter
var shadowFilter:BitmapFilter = new DropShadowFilter(3, 90, 0x252525, 1, 2, 2, 1, 15);
var filterArray:Array = [shadowFilter];
container.filters = filterArray;
container.addEventListener(MouseEvent.MOUSE_UP, zoomHandler);
/*container.addEventListener(MouseEvent.MOUSE_OVER, onOver);
container.addEventListener(MouseEvent.MOUSE_OUT, onOut);*/
addChild(container);
}
}
/*function onOver(e:MouseEvent):void{
var mc1:Sprite = e.currentTarget as Sprite;
tween = new Tween(mc1, "scaleX", Strong.easeOut, mc1.scaleX, (1.1*mc1.scaleX), 0.2, true);
tween = new Tween(mc1, "scaleY", Strong.easeOut, mc1.scaleY, (1.1*mc1.scaleY), 0.2, true);
}
function onOut(e:MouseEvent):void{
var mc2:Sprite = e.currentTarget as Sprite;
tween = new Tween(mc2, "scaleX", Strong.easeOut, mc2.scaleX, (mc2.scaleX/1.1), 0.2, true);
tween = new Tween(mc2, "scaleY", Strong.easeOut, mc2.scaleY, (mc2.scaleY/1.1), 0.2, true);
}*/
function zoomHandler(e:MouseEvent):void
{
var mc:Sprite = e.currentTarget as Sprite;
if(!zoomed && canClick)
{
///* Avoid unwanted clicks
canClick = false;
addChild(screen);
//* Get next highest depth
setChildIndex(mc as DisplayObject, (mc.parent.numChildren - 1));
//* Get position
lastX = mc.x;
lastY = mc.y;
tween = new Tween(mc, "scaleX", Strong.easeOut, mc.scaleX, (3.5*mc.scaleX), 0.5, true);
tween = new Tween(mc, "scaleY", Strong.easeOut, mc.scaleY, (3.5*mc.scaleY), 0.5, true);
if (e.target.parent.x <= 417){
tween = new Tween(mc, "x", Strong.easeOut, mc.x, (stage.stageWidth/2) - ((mc.width*3.5)/2), 0.8, true);
tween = new Tween(mc, "y", Strong.easeOut, mc.y, 0 /*stage.stageHeight / 2 - e.target.parent.height + 15*/, 0.8, true);
} else if(e.target.parent.x > 417){
tween = new Tween(mc, "x", Strong.easeOut, mc.x, 5/*stage.stageWidth / 2 - e.target.parent.width + 15*/, 0.8, true);
tween = new Tween(mc, "y", Strong.easeOut, mc.y, 0/*stage.stageHeight / 3 - e.target.parent.height + 15*/, 0.8, true);
}
tween.addEventListener(TweenEvent.MOTION_FINISH, zoomInFinished);
}
else if(zoomed && canClick) //zoomout to original spot
{
removeChild(infoArea);
tween = new Tween(mc, "scaleX", Strong.easeOut, mc.scaleX,(mc.scaleX/3.5),0.2, true);
tween = new Tween(mc, "scaleY", Strong.easeOut, mc.scaleY,(mc.scaleY/3.5),0.2, true);
tween = new Tween(mc, "x", Strong.easeOut, mc.x, lastX, 0.2, true);
tween = new Tween(mc, "y", Strong.easeOut, mc.y, lastY, 0.2, true);
tween.addEventListener(TweenEvent.MOTION_FINISH, zoomOutFinished);
}
}
function doText(mc):void {
infoArea = new Sprite();
infoArea.name="infoArea";
var infoField:TextField = new TextField();
infoArea.x=0;
infoArea.y=342;
infoArea.graphics.beginFill(0x000000, 0.65);
infoArea.graphics.drawRect(0, 0, 837, 80);
infoArea.graphics.endFill();
infoField.defaultTextFormat=textformat;
infoField.antiAliasType=AntiAliasType.ADVANCED;
infoField.width=800;
infoField.height=60;
infoField.text=dict[mc];
infoField.multiline = true;
infoField.numLines == 4;
infoField.wordWrap = true;
infoField.y=10;
infoArea.addChild(infoField);
addChild(infoArea);
}
function zoomInFinished(e:TweenEvent):void
{
doText(e.currentTarget.obj);
zoomed = true;
canClick = true;
}
function zoomOutFinished(e:TweenEvent):void
{
zoomed = false;
removeChild(screen);
}
There is a crossdomain.xml in the serverB/media folder on serverB that allows serverA access to its files.
Any ideas? Thanks in advance
-
I've tried just about everything. I know there is a simple fix. Any ideas lingering out there?
-
Resolved
Resolved..
Turns out I wasn't in the root of the server, so my crossdomain.xml wasn't loading. Also, I forgot to clear my cache/cookies when refreshing the page
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|