views:

820

answers:

3

Trying to load remote images into a flash sideshow local files work even if I use absolute path. I am updating existing gallery to dynamically pull images from Picasa.

The php works fine and pulls the images from the API. http://domaineseattle.com/gallery/FlashPhotoStack_SRC/gallery.php

But when I pass the XML to flash it wont load remote images.

I added

System.security.loadPolicyFile("http://photos.googleapis.com/data/crossdomain.xml");

to ActionScript but it still wont work.

The scrip for the sideshow is:

1

System.security.loadPolicyFile("http://photos.googleapis.com/data/crossdomain.xml"); 
System.security.allowDomain("*");

MovieClip.prototype.addProperty("onLoad", function () {
    return __onLoadHandler__[this];
}, function (f) {
    if (__onLoadHandler__ == undefined) {
     _global.__onLoadHandler__ = {};
    }
    __onLoadHandler__[this] = f;
});
Math.easeInQuad = function(t, b, c, d) {
    return c*(t /= d)*t+b;
};
Math.easeOutQuad = function(t, b, c, d) {
    return -c*(t /= d)*(t-2)+b;
};
Stage.scaleMode = "noScale";
myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function() {
    nodes = myXML.childNodes;
    // ----------------------
    // find first image
    // ----------------------
    if (topimage.length) {
     for (var i = 0; i<nodes.length; i++) {
      if (nodes[i].attributes.src == topimage) {
       var insert = nodes.slice(0, i);
       nodes.splice(0, i);
       nodes = nodes.concat(insert);
      }
     }
    }
    _root.gotoAndStop(2);
};
//if (_url.indexOf("http")>-1) {
myXML.load("gallery.php");
//} else {
//  myXML.load("gallery.xml");
//}
stop();

2

System.security.loadPolicyFile("http://photos.googleapis.com/data/crossdomain.xml"); 
System.security.allowDomain("*");

function drawOutline(mc, width, height) {
    var wallx = width/2+10;
    var wally = height/2+10;
    var offset = 4;
    // Shadow
    mc.beginFill(0x000000, 20);
    mc.moveTo(-wallx+offset, -wally+offset);
    mc.lineTo(wallx+offset, -wally+offset);
    mc.lineTo(wallx+offset, wally+offset);
    mc.lineTo(-wallx+offset, wally+offset);
    mc.lineTo(-wallx+offset, -wally+offset);
    // Outline
    mc.beginFill(0xFFFFFF, 100);
    mc.lineStyle(2, 0x333333, 100);
    mc.moveTo(-wallx, -wally);
    mc.lineTo(wallx, -wally);
    mc.lineTo(wallx, wally);
    mc.lineTo(-wallx, wally);
    mc.lineTo(-wallx, -wally);
    mc.endFill();
}
// ----------------------
// build placeholders
// ----------------------
loads = [];
stack = [];
depth = 9999;
for (i=0; i<nodes.length; i++) {
    attrs = nodes[i].attributes;
    img = _root.createEmptyMovieClip("image"+i, depth--);
    drawOutline(img, attrs.width, attrs.height);
    img.createEmptyMovieClip("imgholder", 1);
    img.imgholder._x = -attrs.width/2;
    img.imgholder._y = -attrs.height/2;
    img.imgholder.src = attrs.src;
    totalw += img._width;
    totalh += img._height;
    coverw = (img._width>coverw) ? img._width : coverw;
    coverh = (img._height>coverh) ? img._height : coverh;
    img._rotation = (Math.random()*16)-8;
    img._visible = false;
    img._alpha = 0;
    stack.push(img);
    loads.push(img);
}
stack[0]._rotation = 0;
gox = (totalw/nodes.length)*0.9;
goy = (-totalh/nodes.length)*0.4;
// ----------------------
// load images
// ----------------------
function loadimage(id) {
    if (loads[id]) {
     loads[id]._visible = true;
     loads[id].imgholder.loadMovie(loads[id].imgholder.src);
     loads[id].imgholder.onLoad = function() {
      loads[id].imgholder.onEnterFrame = function() {
       if (this._parent._alpha<75) {
        this._parent._alpha += 25;
       } else if (this._parent._alpha<100) {
        this._parent._alpha += 25;
        loadimage(id+1);
       } else {
        delete this.onEnterFrame;
       }
      };
     };
    }
}
loadimage(0);
// ----------------------
// handle swap
// ----------------------
_root.createEmptyMovieClip("Cover", 10000);
Cover.beginFill(0xFFFFFFF, 0);
Cover.moveTo(-coverw/2, -coverh/2);
Cover.lineTo(coverw/2, -coverh/2);
Cover.lineTo(coverw/2, coverh/2);
Cover.lineTo(-coverw/2, coverh/2);
Cover.lineTo(-coverw/2, -coverh/2);
Cover.endFill();
Cover.onRelease = function() {
    // Shuffle the top image to the side
    stack[0].t = 0;
    stack[0].rot = stack[0]._rotation;
    stack[0].changerot = (Math.random()*16)-8-stack[0].rot;
    stack[0].onEnterFrame = function() {
     this.t++;
     this._x = Math.easeInQuad(this.t, 0, gox, 6);
     this._y = Math.easeInQuad(this.t, 0, goy, 6);
     this._rotation = Math.easeInQuad(this.t, this.rot, this.changerot, 6);
     if (this.t == 7) {
      this.swapDepths(depth--);
      this.t = 0;
      this.onEnterFrame = function() {
       this.t++;
       this._x = Math.easeOutQuad(this.t, gox, -gox, 6);
       this._y = Math.easeOutQuad(this.t, goy, -goy, 6);
       if (this.t == 6) {
        delete this.onEnterFrame;
       }
      };
     }
    };
    // Rotate the next image into view
    stack[1]._x = stack[1]._y=0;
    stack[1].t = 0;
    stack[1].rot = stack[1]._rotation;
    stack[1].onEnterFrame = function() {
     this.t++;
     this._rotation = Math.easeOutQuad(this.t, this.rot, -this.rot, 6);
     if (this.t == 6) {
      delete this.onEnterFrame;
     }
    };
    // Move top image to the back of the stack array
    var addback = stack.shift();
    stack.push(addback);
};

Any help would be greatly appreciated.

Thanks!

A: 

If you're trying to use http://domaineseattle.com/gallery/FlashPhotoStack_SRC/gallery.xml, then you'll need to put a root element in there to make it a well-formed XML document.

Also, I see a couple of extraneous backslashes in the xml declaration. ( version=\"1.0\" should be version="1.0" )

ajh1138
I am not using gallery.xml thanks for the answer
A: 

Does it work when you run it directly from the flash ide? In that case you are almost sure it is a permission/security issue, flash flat out refusing to load the images. If it also does not work directly from the flash ide I'd recommend putting some trace statements to print out the urls of the images that it it loading so you can check that they are actually getting parsed correctly (or use the debugger to achieve the same).

Simon Groenewolt
Actually it does not work in the ide or on the local host but I am able to get it to work on a server. I load images fine as long as they are on the same host which is why I am lead to believe that it is a permission/security issue. An Example is http://domaineseattle.com/gallery/FlashPhotoStack_SRC/. It passes local absolute references to images but when I try to pass external images it breaks. I am not sure how to trace(); to find the url it is passing to the file (newbie). Thanks!
Ok so I created a new version that does work in the IDE. I also did a trace and confirmed that the url's where correct. I was so excited up until I realized that loads[id].imgholder.onLoad = function() was empty as soon as a movie clip tried to load a remote image from a different root domain.
Sorry, I don't have any more suggestions. If it works in the IDE you know it _should_ be possible to get it working if you can get the permissions right (especially the external server allowing your flash to download stuff - but it looks like the google one is ok), so I can only say: Keep on trying.
Simon Groenewolt
Just to clarify. I got it to work in the IDE with local files only but have never been able to get remote images from Picasa to load into flash. Thanks for taking the time you did to look into this!
A: 

Ok so I decided to move on from the old AS 1.1 script I was having trouble with and ended up just purchasing http://flash-gallery.com/stack-photo-gallery/. It has everything I needed to get the project done. Thanks for your answers I really appreciate it.