I'm still trying to understand what you are trying to achieve... But you should 
be able to loadn the xml at run time, parse it and load the images from the 
path that you read from the xml ...
C




________________________________
From: Oleg Sivokon <[email protected]>
To: [email protected]
Sent: Mon, March 22, 2010 12:42:48 PM
Subject: Re: [flexcoders] Embedded an image list

   
This depends on the OS and / or the programming / scripting language you know 
to operate it. I had written a tiny C# program to browse a given folder for the 
files of a given type and generate an AS file with embeds, but, I'm sure you 
can do the same with any language that can access to the file system and 
process strings, even AIR can do that.

If you're interested in what I did - here it is:

using System;
using System.Collections. Generic;
using System.Linq;
using System.Windows. Forms;

namespace ResourceBatchProces sor
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application. EnableVisualStyl es();
            Application. SetCompatibleTex tRenderingDefaul t(false);
            Application. Run(new Form1());
        }
    }
}

using System;
using System.Collections. Generic;
using System.Linq;
using System.Text;
using System.Text. RegularExpressio ns;
using System.IO;
using System.Xml;

namespace ResourceBatchProces sor
{
    class MXMLGenerator
    {
        public static string templateStart = 
@"<?xml version=""1.0"" encoding=""utf-8""?>
<fl:Sprite 
xmlns:mx=""http://www.adobe. com/2006/ mxml""
xmlns:fl=""flash.display. *""
xmlns:rs=""org.wvxvws.resource s.*""
>";
        public static string embed =
@"<rs:Resource embed=""@Embed(source='%path%')""/>
";
        public static string templateEnd = "</fl:Sprite>";

        public static Regex nonAlphaNum = new Regex(@"\W", RegexOptions. 
Compiled) ;

        public static void ProcessDirectory( string path)
        {
            DirectoryInfo di = new DirectoryInfo( path);
            FileInfo[] files = di.GetFiles("*.png");
            string filePath;
            string resultFileName = di.Parent.FullName + @"\" + 
                    nonAlphaNum. Replace(di. Name, "_") + ".mxml";
            string resultFile = (string)templateSta rt.Clone( );
            foreach (FileInfo fi in files)
            {
                filePath = ((string)embed. Clone()). Replace("%path%", 
fi.FullName) ;
                resultFile += filePath;
            }
            resultFile += templateEnd;
            XmlTextWriter textWriter = new XmlTextWriter( resultFileName, 
Encoding.UTF8) ;
            textWriter.WriteRaw (resultFile) ;
            textWriter.Close( );
        }

        public static void ProcessDirectory( string[] path)
        {
            //DirectoryInfo[ ] di = new DirectoryInfo[ path.Length] ;
            //int i = 0;
            foreach (string pt in path)
            {
                ProcessDirectory( pt);
                //di.SetValue( new DirectoryInfo( pt), i);
            }
        }
    }
}

using System;
using System.Collections. Generic;
using System.ComponentMod el;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
using System.IO;

namespace ResourceBatchProces sor
{
    public partial class Form1 : Form
    {
        private bool multipleSelected = false;

        public Form1()
        {
            InitializeComponent ();
            this.buttonCreateMX ML.Enabled = false;
            this.buttonSelectFo lder.Click += new EventHandler( 
buttonSelectFold er_Click) ;
            this.buttonCreateMX ML.Click += new EventHandler( buttonCreateMXML 
_Click);
            this.buttonSelectAl lFolders. Click += new EventHandler( 
buttonSelectAllF olders_Click) ;
            this.textSelectedFo lder.TextChanged += new EventHandler( 
textSelectedFold er_TextChanged) ;
            this.Resize += new EventHandler( Form1_Resize) ;
        }

        void buttonSelectAllFold ers_Click( object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog ();
            DialogResult result = dialog.ShowDialog( );
            if (result == DialogResult. OK)
            {
                this.textSelectedFo lder.Text = dialog.SelectedPath ;
            }
            this.multipleSelect ed = true;
        }

        void Form1_Resize( object sender, EventArgs e)
        {
            this.buttonCreateMX ML.Width = this.Width - 30;
            this.buttonSelectFo lder.Width = this.Width - 30;
            this.textSelectedFo lder.Width = this.Width - 30;
            this.buttonSelectAl lFolders. Width = this.Width - 30;
            this.label2. Width = this.Width;
        }

        void textSelectedFolder_ TextChanged( object sender, EventArgs e)
        {
            if (this.textSelectedF older.Text == "")
            {
                this.buttonCreateMX ML.Enabled = false;
            }
            else
            {
                this.buttonCreateMX ML.Enabled = true;
            }
        }

        private void buttonCreateMXML_ Click(object sender, EventArgs e)
        {
            if (this.textSelectedF older.Text == "") return;
            if (this.multipleSelec ted)
            {
                DirectoryInfo di = new DirectoryInfo( this.textSelecte 
dFolder.Text) ;
                DirectoryInfo[ ] dil = di.GetDirectories( );
                string[] paths = new string[dil.Length] ;
                int i = 0;
                foreach (DirectoryInfo d in dil)
                {
                    paths.SetValue( d.FullName, i);
                    i++;
                }
                MXMLGenerator. ProcessDirectory (paths);
            }
            else
            {
                MXMLGenerator. ProcessDirectory (this.textSelect edFolder. 
Text);
            }
        }

        private void buttonSelectFolder_ Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog ();
            DialogResult result = dialog.ShowDialog( );
            if (result == DialogResult. OK)
            {
                this.textSelectedFo lder.Text = dialog.SelectedPath ;
            }
            this.multipleSelect ed = false;
        }
    }
}

+ There was a designer generated code for the form with 2 text inputs and 2 
buttons, but I won't post it because it's to long, and you'll get it the same 
anyway.

Best.

Oleg
 


      

Reply via email to