I had written this code out using Adobe CS3 and have recently upgraded to CS5. I haven’t touched this site in forever and the last time that I did it worked great. The problem is as follows.
type of page: gallery
problem: passing variables
this is the original code that worked last time I checked it but has since stopped working.
function onClick(e:MouseEvent):void
{
trace(e.currentTarget.name);
loadPics(e.currentTarget.name);
}
This is the onClick function. The great thing is that the trace spits out the correct path to the photo. The problem happens in the loadPics() function. As you can see I’m passing the same path (the one that prints to screen correctly) to the function. here’s the code for the function, I apologize if it’s a bit messy.
function loadPics(pic):void
{
photoLoader.source = pic;
photoLoader.y = 10;
photoLoader.x = 10;
loaderHolder.addChild(photoLoader);
//trace (pic.name) yields nothing
//trace (photoLoader.source.name) yields nothing
//trace (photoLoader.name) yields the default instanceXX name
if(photoLoader.source.width > photoLoader.source.height)
{
trace("landscape");
}
else if(photoLoader.source.width < photoLoader.source.height)
{
trace("portrait");
}
else
{
trace("fail");
}
//draw loader background
loaderHolder.graphics.beginFill(0xffffff, 1);
loaderHolder.graphics.drawRect(0, 0, photoLoader.source.width + 20, photoLoader.source.height + 20);
loaderHolder.graphics.endFill();
loaderHolder.x = 230;
loaderHolder.y = 70;
this.addChild(loaderHolder);
}
Please shed some light on this issue. My thumbnails load great, and all the paths are correct. The error that spits out when I click a thumbnail is this
ReferenceError: Error #1069: Property name not found on String and there is no default value.
at portfolio_fla::MainTimeline/loadPics()
at MethodInfo-379()
So I’m deducing that the correct file isn’t being loaded because no file is being loaded at all. Is there a disconnect between the argument I’m passing and the fact that loadPic isn’t reading it as a string? Please help!
Oops almost forgot here are my declarations for the holders
var loaderHolder:Sprite = new Sprite();
var photoLoader:UILoader = new UILoader();
This is the error the debugger outputs when I load the movie
Attempting to launch and connect to Player using URL C:\Documents and Settings\Brodie\Desktop\stephTsai\portfolio.swf
[SWF] C:\Documents and Settings\Brodie\Desktop\stephTsai\portfolio.swf – 426245 bytes after decompression
This is the error the debugger outputs when I click a thumbnail button
gallery/large/test1.jpg
ReferenceError: Error #1069: Property width not found on String and there is no default value.
at portfolio_fla::MainTimeline/loadPics()[portfolio_fla.MainTimeline::frame1:45]
at Function/portfolio_fla:MainTimeline/loadThumbs/portfolio_fla:displayThumbs/portfolio_fla:onClick()[portfolio_fla.MainTimeline::frame1:163]
That first part ‘gallery/large/test1.jpg’ is the program tracing the path at the end of the loadThumbs() function… I’m so lost and I apologize if the code/methodology is weird but I haven’t touched actionscript in forever.
(EDIT—————————————————————–)
I’ve done some investigating…
If I add this in – this.addChild(photoLoader) into the code than it loads a very small version of the picture onto the screen when i click. I can also access the height and width of the photoLoader item. So I’m guessing that what’s screwing it up is that in this section:
if(photoLoader.source.width > photoLoader.source.height)
{
trace("landscape");
}
else if(photoLoader.source.width < photoLoader.source.height)
{
trace("portrait");
}
else
{
trace("fail");
}
and
loaderHolder.graphics.drawRect(0, 0, photoLoader.source.width + 20, photoLoader.source.height + 20);
The program is trying to get the height and width of the string not the picture. Is there a different sytax I should be using or a step I should be taking in order to load picture in correctly before executing the rest of the function?
photoLoader.source is of type string. That’s is what the runtime is complaining, when it tries to fetch width on the source property. What you need to use is photoLoader.width and photoLoader.height.
BTW, I think the code won’t get correct width and height until the resource (the picture) actually gets loaded. So, you’d probably need to wait for Event.COMPLETE before checking on height and width of photoLoader.