A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: URL request from user input?

  1. #1
    Junior Member
    Join Date
    Oct 2006
    Location
    UK
    Posts
    14

    [RESOLVED]URL request from user input?

    Hi, I am trying to make a generic multiple choice quiz, with questions to be loaded from an xml file. The hope is that I can give it to teaching colleagues as a resource, and they can create their own questions by just altering the xml file, as none of them know how to use flash.
    I can make all of it work beautifully for just one xml file's worth of questions, but I'd like to enable people to save several different xml files with different questions, and choose which one to use in the first frame of my swf.
    Here's what I have in the first frame, where there is simply a text input box (inputxml) and a 'Go' button.


    Actionscript Code:
    stop ();
    Go.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);
    var chosenFile:String
    function fl_ClickToGoToNextFrame(event:MouseEvent):void
    {Go.removeEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);
            chosenFile = inputxml.text;
        nextFrame();
    }

    On the next page, it all starts like this:
    Actionscript Code:
    var xmlDoc:XML = new XML();
    var loader:URLLoader = new URLLoader();
    var req:URLRequest = new URLRequest("Questions2.xml");
    loader.load(req);

    loader.addEventListener(Event.COMPLETE, completeHandler);
    function completeHandler(evt:Event):void {
        loader.removeEventListener(Event.COMPLETE, completeHandler);
        xmlDoc = XML(evt.target.data);
    quizTitle.text = String(xmlDoc.quizTitle.@title);
    };

    It works as long as I specify
    Actionscript Code:
    var req:URLRequest = new URLRequest("Questions2.xml");
    but when I try to swap this for
    Actionscript Code:
    var req:URLRequest = new URLRequest(chosenFile);
    where chosenFile is "Questions2.xml", it won't work, and gives me this error:
    Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:////Volumes/Macintosh%20HD/Users/millycampling/Documents/00%20Flash/Multiple%20Choice/
    Questions2.xml

    I have just changed over from Flash Pro 8 to CS5, and AS3 is still a bit new to me - am I doing something really daft?
    Last edited by millysquires; 11-28-2010 at 12:25 PM.

  2. #2
    Member
    Join Date
    Apr 2010
    Posts
    87
    check if your input textfield is not multiline.
    there's this problem with multiline textfield where '\n' symbol is inserted in front of the text.

  3. #3
    Junior Member
    Join Date
    Oct 2006
    Location
    UK
    Posts
    14
    Is it wrong that I love you?!

    I changed it to single line (you were right, I had been using multiline before and not changed this one) and it works beautifully

    Thank you!

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