Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1

    Default Accessing variables from text files

    Hi!

    Say I've got a textfile 'data.txt' with these variables:

    //appears in the first dropdown
    &selection=fruits,cars,bottled water

    //appears in the second dropdown, based on selection in first one
    &items0=apple,pear,mango,plum
    &items1=buick,dodge,ford,oldsmobile
    &items2=evian,perrier,spa,bar-le-duc

    I thought something like this ought to do the trick:

    Code:
    srOverzicht = new LoadVars();
    srOverzicht.load("data.txt");
    srOverzicht.onLoad = function(success) {
    	if (success) {
                    //split selection into an array
    		srArray = this.selection.split(",");
    
                    //display items in combobox, stick 'items'+$i as data field 
    		for &#40;$i=0;$i<srArray.length;$i++&#41; &#123;
    			dropdownOne.addItem&#40;srArray&#91;$i&#93;,"items"+$i&#41;;
    		&#125;
    	&#125;
    &#125;
    
    //setting change handler
    dropdownOne.setChangeHandler&#40;"DisplaySelected"&#41;;
    
    function DisplaySelected&#40;&#41; &#123;
                    //identify selection from dropdownone
                    $selected = dropdownOne.getSelectedItem&#40;&#41;.data;
    
                    stOverzicht = new LoadVars&#40;&#41;;
    		stOverzicht.load&#40;"data.txt"&#41;;
    		stOverzicht.onLoad = function&#40;success&#41; &#123;
    
    			if &#40;success&#41; &#123;
                                    //load dropdowntwo based on selection
    				stArray = this.$selected.split&#40;","&#41;;
    
                                    //display items in dropdowntwo
    				for &#40;$i=0;$i<stArray.length;$i++&#41; &#123;
    					dropdownTwo.addItem&#40;stArray&#91;$i&#93;&#41;;
    				&#125;
    			&#125;
    		&#125;
    &#125;
    I think it's the line
    Code:
    stArray = this.$selected.split&#40;","&#41;;
    that messes things up. Any idea how I can get around this? The only solution I see at this point, is splitting all data up in a different text file each. I'd like it to work another way, if possible.

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    The easy way to do it is to use seperate text files and load them accordingly. I notice that you are using the data property of the combobox. I find it easier to use the label property and have the labels the name of the text file to be loaded. I use something similar for an MP3 player. The user selects the song title from the combobox and a play button just uses the label property of that combobox to load a song named the same. Here is a demo of loading multiple text files for use when needed....
    Code:
    fillMarina = new LoadVars&#40;&#41;;
    fillCampground = new LoadVars&#40;&#41;;
    fillStorage = new LoadVars&#40;&#41;;
    fillTotal = new LoadVars&#40;&#41;;
    function getFile&#40;&#41; &#123;
    	targetFile = _root.cbox.getSelectedItem&#40;&#41;.label+".txt";
    	fillMarina.load&#40;targetFile&#41;;
    	fillCampground.load&#40;targetFile&#41;;
    	fillStorage.load&#40;targetFile&#41;;
    	fillTotal.load&#40;targetFile&#41;;
    	fillMarina.onLoad = function&#40;success&#41; &#123;
    		if &#40;success&#41; &#123;
    			accountsList.removeAll&#40;&#41;;
    			Display = this.myArea;
    			accountsList.label.addItem&#40;""&#41;;
    			for &#40;i=0; i<=this&#91;"myPerson" + i&#93;.length; i++&#41; &#123;
    				accountsList.addItem&#40;this&#91;"myPerson" + i&#93;&#41;;
    			&#125;
    		&#125; else &#123;
    			trace&#40;"Couldn't load"&#41;;
    		&#125;
    	&#125;;
    &#125;
    fillCampground.onLoad = function&#40;success&#41; &#123;
    	if &#40;success&#41; &#123;
    		accountsList.removeAll&#40;&#41;;
    		Display = this.myArea;
    		for &#40;i=0; i<=this&#91;"myPerson" + i&#93;.length; i++&#41; &#123;
    			accountsList.addItem&#40;this&#91;"myPerson" + i&#93;&#41;;
    		&#125;
    	&#125; else &#123;
    		trace&#40;"Couldn't load"&#41;;
    	&#125;
    &#125;;
    fillStorage.onLoad = function&#40;success&#41; &#123;
    	if &#40;success&#41; &#123;
    		accountsList.removeAll&#40;&#41;;
    		Display = this.myArea;
    		for &#40;i=0; i<=this&#91;"myPerson" + i&#93;.length; i++&#41; &#123;
    			accountsList.addItem&#40;this&#91;"myPerson" + i&#93;&#41;;
    		&#125;
    	&#125; else &#123;
    		trace&#40;"Couldn't load"&#41;;
    	&#125;
    &#125;;
    fillTotal.onLoad = function&#40;success&#41; &#123;
    	if &#40;success&#41; &#123;
    		accountsList.removeAll&#40;&#41;;
    		Display = this.myArea;
    		for &#40;i=0; i<=this&#91;"myPerson" + i&#93;.length; i++&#41; &#123;
    			accountsList.addItem&#40;this&#91;"myPerson" + i&#93;&#41;;
    		&#125;
    	&#125; else &#123;
    		trace&#40;"Couldn't load"&#41;;
    	&#125;
    &#125;;
    cbox.onRelease = function&#40;&#41; &#123;
    	if &#40;_root.cbox.getSelectedItem&#40;&#41;.label==Marina&#41; &#123;
    		getFile&#40;&#41;;
    		fillMarina = null;
    		fillCampground = new LoadVars&#40;&#41;;
    		fillStorage = new LoadVars&#40;&#41;;
    		fillTotal = new LoadVars&#40;&#41;;
    	&#125; else if &#40;_root.cbox.getSelectedItem&#40;&#41;.label==Campground&#41; &#123;
    		getFile&#40;&#41;;
    		fillCampground = null;
    		fillMarina = new LoadVars&#40;&#41;;
    		fillStorage = new LoadVars&#40;&#41;;
    		fillTotal = new LoadVars&#40;&#41;;
    	&#125; else if &#40;_root.cbox.getSelectedItem&#40;&#41;.label==Storage&#41; &#123;
    		getFile&#40;&#41;;
    		fillStorage = null;
    		fillMarina = new LoadVars&#40;&#41;;
    		fillCampground = new LoadVars&#40;&#41;;
    		fillTotal = new LoadVars&#40;&#41;;
    	&#125; else if &#40;_root.cbox.getSelectedItem&#40;&#41;.label==Total&#41; &#123;
    		getFile&#40;&#41;;
    		fillTotal = null;
    		fillMarina = new LoadVars&#40;&#41;;
    		fillCampground = new LoadVars&#40;&#41;;
    		fillStorage = new LoadVars&#40;&#41;;
    	&#125;
    &#125;
    http://ntdesigns.net/demo/comboboxloadfile.zip

    This is a demo of a combobox used to load resort information dependent on the combobox selection. The loaded content can load other content from another combobox on selection.

    Hope it helps
    NTD

  4. #3
    Join Date
    Jun 2007
    Location
    Virginia
    Posts
    3

    Default I also have a Text field problem

    Create text field and save button at run time:

    this.createTextField("tNotes", this.getNextHighestDepth(), 75, 25, 400, 20);
    this.attachMovie("SaveButtonSymbol", "mcSaveButton", this.getNextHighestDepth());

    Set field properties at run time
    tNotes.border = true;
    tNotes.type = "input";
    tNotes.textColor = 0xFFFFFF;
    tNotes.wordWrap = true;

    Create shared object
    var lsoNotes:SharedObject = SharedObject.getLocal("notes");
    tNotes.text = (lsoNotes.data.notes == undefined) ? "" : lsoNotes.data.notes;

    place save button at runtime
    . mcSaveButton._x = 400;
    mcSaveButton._y = 50;

    Create save button function
    mcSaveButton.onRelease = function():Void
    lsoNotes.data.notes = tNotes.text;
    lsoNotes.flush();
    }
    }

    tNotes or “notes” holds information in an administration field that is not accessible by common users. It feeds the news ticker at the bottom of this flash demo.

    http://blog.myspace.com/friendsoffoxnews

    I am getting an undefined error when this code is activated as can be seen at the bottom of the blog header

    tic_mc.onEnterFrame = function(){
    tic_mc.text_txt.text = ("tNotoes", lsoNotes.getNextHighestDepth(“notes”))
    }

    any help would be great.

    D Ape

  5. #4
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    I dont see you using the load method to load the shared object but beyond that, i dont see any glareing code errors... except for possibly calling for the data in an enterframe event. Maybe try the setInterval method for loading the data. It would cut down on processor usage.

    NTD
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

  6. #5
    Join Date
    Jun 2007
    Location
    Virginia
    Posts
    3

    Default load method

    yep i would agree that is a problem...where and how should i place it? i have tried several times and only gotten a NUll response.

    D Ape

  7. #6
    Join Date
    Jun 2007
    Location
    Virginia
    Posts
    3

    Default this is a mock up

    as for the processor usage, this code is a mock up for a larger project, that i will intergrate later.

    D Ape

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Replies: 8
    Last Post: 06-06-2007, 12:43 PM
  2. Dynamic Variables
    By gotoandpay in forum Newbies
    Replies: 0
    Last Post: 05-25-2006, 01:26 AM
  3. Dynamic Variables
    By n4rc071X in forum Flash Scripting
    Replies: 1
    Last Post: 03-29-2006, 07:33 PM
  4. variables
    By KingKong in forum Flash Scripting
    Replies: 8
    Last Post: 12-24-2004, 02:35 AM
  5. Scripting Help using Variables
    By sgiff in forum Advanced Flash
    Replies: 3
    Last Post: 03-28-2004, 09:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial