PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Passing Flashvars into public class and assign this string as path to XML????
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Passing Flashvars into public class and assign this string as path to XML????

Hybrid View

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180

    Passing Flashvars into public class and assign this string as path to XML????

    I am trying to pass FlashVars into public class EventDispatcher to set the path to data.xml. I need it because the name and path of the xml file will be dynamically created. I need to use Flashvar in order to access the correct path.
    I was able to pass Flashvar from html page on timeline this way:
    Actionscript Code:
    var Flashvars:String = LoaderInfo(stage.loaderInfo).parameters.xmlfile;
    Then, I was able to use it with new UrlRequest;
    Actionscript Code:
    var request:URLRequest = new URLRequest(Flashvars);

    This method works really good, but this solution only works on timeline.
    I need to implement this technique in the class. Before I setup a static var for with the path to xml file. I'd like to be able to get FlashVar withing this class and assign this string to 'public static var DATA_XML_URL:String' I have there. This way I can pass Flashwar to the project I already have.
    I am wondering if it is doable from what I described. I already spent a gay for it but obviously stack here. Any help is highly appreciate.
    Below is the class:

    Actionscript Code:
    import flash.events.Event;
        import flash.events.EventDispatcher;
        import flash.display.Sprite;
        import flash.display.LoaderInfo;
        import flash.display.MovieClip;
        import flash.display.Stage;

       
        public class ConfigManager extends EventDispatcher {
           
           
            //private var loaderInfo:LoaderInfo;
            private var _targetLoaderInfo:LoaderInfo;
           
            // The name of the event to be fired when configuration is read
            public static const CONFIG_LOADED:String = "configLoaded";
           
            // Location of the data xml file
            public static var DATA_XML_URL:String = "xml/data.xml";
           
            public static var PHOTO_DIR:String = "images/profile/"
            private var configXMLLoader:XMLLoader;
           
            // Xml data
            private var xml:XML;
           
            // A reference to the ConfigManager
            private static var _configManager:ConfigManager;
           
            private var test1:String = "";
       
           
            public function ConfigManager(singletonEnforcer:SingletonEnforcer) {           
                // NOTHING HERE
            }          
           
           
           
            public function load():void {
                // Create a new XMLLoader object
               
                //DATA_XML_URL = LoaderInfo(stage.loaderInfo).parameters.xmlfile;
       
                //Or it can be this way
                /*if (LoaderInfo(this.parent.parent.loaderInfo).parameters.xmlfile !== undefined){
                    test1 = LoaderInfo(this.parent.parent.loaderInfo).parameters.xmlfile;
                    DATA_XML_URL = test1;
                   
                }*/

                init();
            }
           
           
            public function init():void {
               
                configXMLLoader = new XMLLoader(CONFIG_XML_URL);
               
                // Add an event listener to be dispatched when xml is parsed.
                configXMLLoader.addEventListener(XMLLoader.XML_LOADED, onConfigXMLLoaded);
               
                // Start loading the file
                configXMLLoader.load();
               
            }
           
            private function readConfig(xml:XML):void {
                // Read configurations here
                PHOTO_DIR = xml.@photoDir;
            }
           
            //This method is called when the configuration file is loaded.       
            private function onConfigXMLLoaded(evt:Event):void {
               
                // Read the setting values from the configuration file
                readConfig(configXMLLoader.getXML());
                dispatchEvent(new Event(ConfigManager.CONFIG_LOADED));

            }
            // Returns the configuration manager.
            public static function getInstance():ConfigManager {
               
                if (_configManager == null) {
                    _configManager = new ConfigManager(new SingletonEnforcer());
                }
               
                return _configManager;
               
            }
           
        }
       
    }
    Last edited by vladc77; 05-29-2010 at 07:08 AM.
    Best regards
    Vlad,

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You probably have a Document class. Get the Flashvars value in the Document class and then pass it on to the other class.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Thank you for the response. I tried to make it work but still cannot finish this up. I'd like to find out what I am missing here.

    I have a Document class. I am able to get the Flashvars Value, but I fail to pass this string to the class needed. I have SingletonEnforcer which possible is causing the problem, but I cannot remove it.

    I get Flashvars:
    Actionscript Code:
    _flashVars = stage.loaderInfo.parameters.xmlfile:

    I pass the variable value to class:
    Actionscript Code:
    var _config:ConfigManager = new ConfigManager(_flashVars);
    Below is the main-document class:
    Actionscript Code:
    package com {

    import flash.display.*;

    import flash.events.*;

    import flash.display.DisplayObject;

    import flash.display.Loader;

    import flash.display.LoaderInfo;

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.events.Event;

     

    import flash.net.URLRequest;

    import flash.net.navigateToURL;

    import flash.display.Stage;

    import com.ConfigManager;

     

    public class Main extends MovieClip {

    private var _flashVars:String = "";

    private var _config:ConfigManager;

     

    public function Main():void {

    addEventListener(Event.ADDED_TO_STAGE, init);

    }

     

    public function init(e:Event):void {

    removeEventListener(Event.ADDED_TO_STAGE, init);

    _flashVars = stage.loaderInfo.parameters.xmlfile;

    var _config:ConfigManager = new ConfigManager(new SingletonEnforcer(), _flashVars);

    }

     

    public function get flashVars():String {

    return _flashVars;

     

    }

    }

    }


    I change const to variable and do not assign any value to it:

    public static var DATA_XML_URL:String;

    I add new variable:

    private var xmlVar1;

    I am passing Flashvars this way:

    Actionscript Code:
    public function ConfigManager(singletonEnforcer:SingletonEnforcer, _flashVars) {

    xmlVar = _flashVars;

    //I did this way too:

    // DATA_XML_URL = _flashVars;

    }

    I assign DATA_XML_URL in init function:

    Actionscript Code:
    DATA_XML_URL = xmlVar;

    The ConfigManager class

    ConfigManager class below:

    Actionscript Code:
    package com {

    import flash.events.Event;

    import flash.events.EventDispatcher;

    import flash.display.Sprite;

    import flash.display.LoaderInfo;

    import flash.display.MovieClip;

    import flash.display.Stage;

     

    public class ConfigManager extends EventDispatcher {

    // The name of the event to be fired when configuration is read

    public static const CONFIG_LOADED:String = "configLoaded";

    // Location of the data xml file

    // I need to assign FlashVars to DATA_XML_URL instead of the string that assigned now

     

    //public static var DATA_XML_URL:String = "xml/data.xml";

    public static var DATA_XML_URL:String;

     

    public static var PHOTO_DIR:String = "images/profile/"

     

    private var configXMLLoader:XMLLoader;

    // Xml data

    private var xml:XML;

    // A reference to the ConfigManager

    private static var _configManager:ConfigManager;

     

    private var xmlVar1;

     

    public function ConfigManager(singletonEnforcer:SingletonEnforcer, _flashVars) {

    xmlVar1 = _flashVars;

    }

    public function load():void {

    init();

    }

    public function init():void {

    // Create a new XMLLoader object

     

    //Assign FlashVars to - DATA_XML_URL

    DATA_XML_URL = xmlVar1;

     

    configXMLLoader = new XMLLoader(CONFIG_XML_URL);

    // Add an event listener to be dispatched when xml is parsed.

    configXMLLoader.addEventListener(XMLLoader.XML_LOADED, onConfigXMLLoaded);

    // Start loading the file

    configXMLLoader.load();

    }

    private function readConfig(xml:XML):void {

    // Read configurations here

    PHOTO_DIR = xml.@photoDir;

    }

    //This method is called when the configuration file is loaded.

    private function onConfigXMLLoaded(evt:Event):void {

    // Read the setting values from the configuration file

    readConfig(configXMLLoader.getXML());

    dispatchEvent(new Event(ConfigManager.CONFIG_LOADED));

    }

    // Returns the configuration manager.

    public static function getInstance():ConfigManager {

     

    if (_configManager == null) {

    _configManager = new ConfigManager(new SingletonEnforcer());

    }

    return _configManager;

    }

     

    }

     

    }
    Last edited by vladc77; 06-01-2010 at 08:12 AM.
    Best regards
    Vlad,

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You can create a getter - setter and pass the variable to that and then get the variable in the singleton from the getter - setter.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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