dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] as3(new project) load image from an xml created menu

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    12

    resolved [RESOLVED] as3(new project) load image from an xml created menu

    I'm trying to load an image from a xml created menu
    my menu is created and when I press a button within the menu my text in my linkTo node appears in my textfield called contents. this part works great.
    but when I try to load my image that goes with the text is where my problem is.

    EDIT: when I trace (item.image); I get " images/20.jpg" on first button and the second button traces "images/21.jpg" so the xml nodes are correct.
    Please can someone help me THANKS A MILLION in advance
    Sincerely Xiaz


    1st try
    Code:
    //assign a "linkTo" variable. this contains the url where the menu will link to when clicked
    menuItem.linkTo = button.linkTo.toString();
    //assign a "image" variable. this contains the url where the menu will link to when clicked
    menuItem.image = button.image.toString();
    
    function itemClicked(e:Event):void (
         var item:MenuItem = e.target as MenuItem;
         contents.htmlText = item.linkTo;
    
    /////////PROBLEM AREA////////////////////////////////////////////////////////
         imageloader.load(new URLRequest (item.image));
         trace (item.image);
    //traces Error#1034: Type Coercion failed: cannot convert "images/20.jpg" to flash.net.URLRequest. 
    at Vertical_fla::MainTimeline/itemClicked
    2nd try
    Code:
    var urlRequest:URLRequest = new URLRequest(item.image);
     imageloader.load(urlRequest);
     trace(urlRequest);
    //traces "[object URLRequest]"
    3rd try
    Code:
    var request:URLRequest = new URLRequest(item.image);
    var variables:URLVariables = new URLVariables();
    request.data = variables;
    imageloader.load(request);
    trace(request)
    //traces "[object URLRequest]" and "Error #2044 Unhandled IOErrorEvent:.text=Error #2035: URL Not Found"
    Last edited by Xiaz; 08-20-2010 at 04:52 AM.

  2. #2
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    Where are you testing - locally or on a server? Try with an absolute path/url
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    12
    Smilev thanks for commenting and trying to help
    to answer your question
    I'm testing locally for it will not be for the web.

    can you please give an example to try? for I never used absolute path/url

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    12
    I did a quick google and tried
    Code:
    var urlRequest:URLRequest = new URLRequest(item.image);
    navigateToURL(urlRequest,'item.image');
    it opened a web browser with the image in it, but I need my image to load into my imageloader, any Ideas how to do that?

  5. #5
    Senior Member
    Join Date
    May 2002
    Posts
    1,017
    I dont see why it wouldnt work if the path is right.

    Try something like this and see if it is going to work:

    Code:
    var ldr:Loader = new Loader();
     var url:String = "images/20.jpg";
     var urlReq:URLRequest = new URLRequest(url);
     ldr.load(urlReq);
     addChild(ldr);
    Last edited by Smilev; 08-20-2010 at 06:17 AM.
    while (2+2 == 4) {
    drink ("bourbon");
    }
    gotoAndStop("bed");

  6. #6
    Junior Member
    Join Date
    Aug 2010
    Posts
    12
    I wrote that and when I clicked on any button the certain image appeared.
    so I tried
    Code:
     var url:String = item.image;
    and works great all images load when called THANKS A MILLION

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center