Flash CS4 Loader Class: Image Loads Initially, but Error Returned When Loading New Image
This is extremely difficult to explain in the title... First, here is my code in Actionscript:
var digitalGallery:Loader = new Loader();
digitalGallery.x = 730
digitalGallery.y = 210
digitalGallery.load(new URLRequest("images/nair_evanescentautumn.png"));
addChild(digitalGallery);
function dgtlLatest(event:MouseEvent):void {
if(event.target == new_thumb1) {
digitalGallery.load(new URLRequest("images/iilu_evanescantautumn.png"));
}
else if(event.target == new_thumb2) {
digitalGallery.load(new URLRequest("images/daem_evanescantautumn.png"));
}
else if(event.target == new_thumb3) {
digitalGallery.load(new URLRequest("images/moon_evanescantautumn.png"));
}
else if(event.target == new_thumb4) {
digitalGallery.load(new URLRequest("images/dael_evanescantautumn.png"));
}
}
function dgtlGalery(event:MouseEvent):void {
if(event.target == gal_thumb1) {
digitalGallery.load(new URLRequest("images/kryo_evanescantautumn.png"));
}
else if(event.target == gal_thumb2) {
digitalGallery.load(new URLRequest("images/nair_evanescantautumn.png"));
}
else if(event.target == gal_thumb3) {
digitalGallery.load(new URLRequest("images/lite_evanescantautumn.png"));
}
else if(event.target == gal_thumb4) {
digitalGallery.load(new URLRequest("images/oasi_evanescantautumn.png"));
}
}
new_thumb1.addEventListener(MouseEvent.CLICK,dgtlLatest);
new_thumb2.addEventListener(MouseEvent.CLICK,dgtlLatest);
new_thumb3.addEventListener(MouseEvent.CLICK,dgtlLatest);
new_thumb4.addEventListener(MouseEvent.CLICK,dgtlLatest);
gal_thumb1.addEventListener(MouseEvent.CLICK,dgtlGalery);
gal_thumb2.addEventListener(MouseEvent.CLICK,dgtlGalery);
gal_thumb3.addEventListener(MouseEvent.CLICK,dgtlGalery);
gal_thumb4.addEventListener(MouseEvent.CLICK,dgtlGalery);
This script is for a loader image gallery in flash, as part of a class assignment. What happens is that in flash, when I open the swf file, the initial image (images/nair_evanescentautumn.png) will load fine. However, clicking on any thumbnail image (including the exact same images/nair_evanescentautumn.png), will result in an error saying the file cannot be found.
I cannot figure out why it is doing this... I've tested it over. Clicking each thumbnail does go to the correct position in the two separate functions. All said full-size image links are in the folder images/, and replacing the initial loader image will load the other images in place of the default one. However, clicking on any thumbnail still results in URL not found, even though everything works correctly.
开发者_如何学JAVAThis is just driving me crazy... it can't be this difficult to create a simple gallery.
The assignment is due Wednesday, though... I'm sure I can ask my instructor in-class, but I'd prefer to have it done before then, and I can't think of anything else to do except post this.
All help is greatly appreciated...
EDIT:
Sorry about not posting the error...
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
EDIT 2:
Here's a link to the entire set of files:
http://www.tsr-online.org/flash/index.swf
My server won't allow access to the /flash folder index, but I can give the directory listing.
/flash directory: /images (contains all images) /cmsn (contains commissions.swf subpages) index.swf home.swf blog.swf traditional.swf digital.swf photography.swf commissions.swf
Before anyone asks why I'm putting this kind of content into a flash site, I'm not--this is only for a class assignment. I'm just trying to figure out why my images aren't loading right when I'm only doing the exact same thing in the functions as I am on the other pages.
Of note, commissions.swf has the exact same feature, just with swf files loaded instead, and it works perfectly fine. home, traditional, digital, and photography all have the image gallery, and all have the same issue (I only referenced one page because if I can fix one page I should be able to fix all of them).
As for the artworks, they are all my fiance's. The website design was built for her, and I used the website design for this project because I didn't want to have to build an entirely new interface design. Since the project also required a gallery, I felt that this interface would work just fine.
You have spelling mistakes in your code. That's all the issue is. Example from your own code:
else if(event.target == new_thumb2) {
digitalGallery.load(new URLRequest("images/daem_evanescantautumn.png"));
}
When in fact the spelling is:
http://www.tsr-online.org/flash/images/daem_evanescentautumn.png
Note the exact issue is "vanesc a ntautumn.png" when it should be "vanesc e ntautumn.png."
Fix the spelling in your code above and all should be well.
Since I cannot make a comment on your post because of the strange restrictions I have to write an answer (which is a question to you): Why do you try to load the same image twice?
You're kinda going about it in a really roundabout sort of way anyway - try this out:
var digitalGallery:Loader;
var thumbs:Array = ['new_thumb1',
'new_thumb2',
'new_thumb3',
'new_thumb4',
'gal_thumb1',
'gal_thumb2',
'gal_thumb3',
'gal_thumb4']
var images:Array = ['iilu_evanescantautumn',
'daem_evanescantautumn',
'moon_evanescantautumn',
'dael_evanescantautumn',
'kryo_evanescantautumn',
'nair_evanescantautumn',
'lite_evanescantautumn',
'oasi_evanescantautumn']
setupThumbs()
function setupThumbs(){
for (var i=0; i<thumbs.length; i++){
var thumb = this.getChildByName(thumbs[i])
thumb.id = i
thumb.addEventListener(MouseEvent.CLICK, loadImage);
}
}
function loadImage(event:MouseEvent){
var id = event.currentTarget.id
digitalGallery = new Loader();
digitalGallery.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
digitalGallery.load(new URLRequest("images/"+images[id]+".png"));
}
function loadComplete(event:Event):void {
trace("Complete");
addChild(digitalGallery)
digitalGallery.x = 730;
digitalGallery.y = 210;
}
精彩评论