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

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
How I can get Flashvars value from a package as class, not from the timeline? - Page 2
A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41

Thread: How I can get Flashvars value from a package as class, not from the timeline?

  1. #21
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    ok then where are you calling all your classes from? where are you calling
    PHP Code:
    var config:ConfigManager = new ConfigManager(); 
    ????

    put root.loaderInfo.parameters["xmlfile"] in var config:ConfigManager = new ConfigManager(); as a parameter.

    why do you need ["xmlfile"] ???? is ConfigManager being called more than one time per application?
    ~calmchess~

  2. #22
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    No. I am calling all classes by assigning a path in Actionscript 3.0 Settings in Preference. I need to call it from html page because the xml files will loaded accroding to html page is loaded.
    Best regards
    Vlad,

  3. #23
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    well you are programming incorrectly.........you should have a document class from where you call all your class from ....name this main.as and attach it by clickin on an empty grey part of the stage choose properties and then fill in document class to point at main.as make sure you extend main.as as movieClip
    ~calmchess~

  4. #24
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Perhaps, we are talking about different things. I just want to make sure I explained everything correctly. I just want to get to the bottom of it to make sure I have a good habit working on actionscript projects.
    I created a project with one fla file, created 'src' folder to keep all classes I use, and other folders for images and xml. The way I link fla file to the classes is setting source path in ActionScript 3.0 Advanced Settings. To get there I had to do this:
    In flash menu I go to Edit/Preferences, then I choose Actionscript tab and from that tab choose Language - Actionscript 3.0 Settings. In actionscript 3.0 Setting window I can define a source path to the class collection I use.
    I used this approach few times and it worked always fine. I'd like to verify if this is really a wrong way to go. Please can you point me to the information about your approach you were telling about. I'd like to try it. Thank you again.
    Last edited by vladc77; 05-27-2010 at 10:40 PM.
    Best regards
    Vlad,

  5. #25
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    The technique isn't really documented via tutorial its more like a way of structuring a document from techniques in books such as Essential ActionScript 3.0 and techniques suggested to me on this forum by admins such as 5TonsOfFlax.......here is one of my main/document class

    PHP Code:
    package Main{
        
    import flash.display.*;
        
    import flash.net.*;
        
    import flash.events.NetStatusEvent;
        
    import flash.events.*;
        
    import NetConnections.NetConnections;
        
    import UserList.UserList;
        
    import SharedObjects.SharedObjects;
        
        
    import Chat.Chat;
        
    import Call.Call;
        
    import XMLang.Settings;
        
        
    import flash.net.*;
        
    import flash.xml.*;
        
        
        public class 
    Client_Main extends Sprite {
             
            
            private var 
    so:SharedObjects;
            
            public var 
    chat:Chat;
            public var 
    calls:Call;
            
            public var 
    userName:*;
            public var 
    nc1:NetConnections;
            
            private var 
    instanceID1:*;
            private var 
    xmlSettings:Settings;
            private var 
    ipadd:*;
            private var 
    clientID;
            public var 
    uList:UserList;
            public var  
    width0:Number;
            public var  
    height0:Number;
            public function 
    Client_Main() {
                
    stage.scaleMode StageScaleMode.NO_SCALE;
                
    stage.align StageAlign.TOP_LEFT;
                
    so = new SharedObjects(nc1);
                
    uList = new UserList(nc1,so.so2,so.so3);
                
    addChild(uList);
                
    calls = new Call(nc1);
                
    chat = new Chat(so.so1,nc1,userName,width0,height0);
                
    addChild(chat);

            }
            
            }

    This is just a example document class but here is how it breaks down.
    1.import all class packages
    2. assign variable names for each class
    3. call the class package with myclassvariablename = new myimportedclassPackagename();
    4. if you have used addChild in the class pacakge then add child here also
    addChlid(myclassvariablename);
    ~calmchess~

  6. #26
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Great, I will try this technique in my next project. Now, It will take some time for me to make within my existing project. I believe I still should be able to pass the Flashvar string to eventDispartcher class. As I understood correctly, I should call ConfigManager Class and pass the variable from main timeline. Can I call ConfigManager from the main timeline? I think I am lost here.
    Best regards
    Vlad,

  7. #27
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    Don't try it on your next project you must use it on this one take the time to write it out won't take you as long as you think and your application will become much easier to handle.I didn't write the above post so you can ask a thousand un answerable questions related to your project.....I wrote it so you can organize and properly write your program.
    ~calmchess~

  8. #28
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    I finally managed to create Main.as document class. Thank you for the lead.
    Last edited by vladc77; 05-29-2010 at 06:28 AM.
    Best regards
    Vlad,

  9. #29
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    I finally managed to create Main.as document class. Thank you for the lead. Now, I really want to get to the point I can pass flashvars into 'public class ConfigManager extends EventDispatcher'. I still cannot complete it. I need to pass flashvar into "DATA_XML_URL'. It is still not goiung well. When I call configManager class from document root I am getting the error:

    Actionscript Code:
    1136: Incorrect number of arguments.  Expected 1.

    I imported and call this class:
    Actionscript Code:
    import src.ConfigManager;
    Actionscript Code:
    var config:ConfigManager = new ConfigManager();

    Do you mind to help me to finish it? Thank you in advance.

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


    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;
       
           
            public function ConfigManager(singletonEnforcer:SingletonEnforcer) {           
                // NOTHING HERE
            }          
           
           
           
            public function load():void {
               
       
       
                init();
            }
           
           
            public function init():void {
                // Create a new XMLLoader object
               
                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 06:42 AM.
    Best regards
    Vlad,

  10. #30
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    pass the flash var from main to config manager .......you will have to chage xmlVar to the actual FlashVarName
    PHP Code:
    var config:ConfigManager = new ConfigManager(root.loaderInfo.parameters.xmlVar); 
    intialize all varaibles here but don't assign the variable do that in the constructor like i've done with xmlVar1.

    create class var
    PHP Code:
     public class ConfigManager extends EventDispatcher {                
    private var 
    xmlVar1


    assign passed flashVar to class var ("asssing value to all other variables here too") so it can be used outside the constructor
    PHP Code:

     
    public function ConfigManager(passedFlashVar) {  xmlVar1 xmlVar;   } 



    now use xmlVar1 with your xml string

    PHP Code:
    DATA_XML_URL xmlVar1
    ~calmchess~

  11. #31
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Thak you for the quick reply. I have problem in this step:
    Actionscript Code:
    assign passed flashVar to class var ("asssing value to all other variables here too") so it can be used outside the constructor
    public function ConfigManager(passedFlashVar) {  xmlVar1 = xmlVar;   }
    I have 'ConfrgManager' constructor I have this:
    Actionscript Code:
    public function ConfigManager(singletonEnforcer:SingletonEnforcer, ) {
            }

    If I assign anything there, then I have erroe:
    1136: Incorrect number of arguments. Expected 2.
    1120: Access of undefined property xmlVar.
    How I define 'passedFlashVar' in here?

    Actionscript Code:
    public function ConfigManager(passedFlashVar) {  xmlVar1 = xmlVar;   }

    Thnak you.
    Best regards
    Vlad,

  12. #32
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    oh this is a mess.............what does(singletonEnforcer:SingletonEnforcer) do? where is the parameter getting its data?
    ~calmchess~

  13. #33
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    PHP Code:
    var config:ConfigManager = new ConfigManager(null,root.loaderInfo.parameters.xmlVar); 
    PHP Code:
    public function ConfigManager(singletonEnforcer:SingletonEnforcer,passedflashVar) {    xmlVar1 =passedFlashVar;    } 
    PHP Code:
     
    ~calmchess~

  14. #34
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    If you look at the ConfigManager class I included above it might explain why I have singelton. I changed the constructor and I am still getting the error:
    1136: Incorrect number of arguments. Expected 2.
    1120: Access of undefined property xmlVar.
    1049: Illegal assignment to a variable specified as constant.
    and more
    Line 188 is located in here:
    Actionscript Code:
    public static function getInstance():ConfigManager {
               
                if (_configManager == null) {
                    _configManager = new ConfigManager(new SingletonEnforcer());
                }
               
                return _configManager;
               
            }

    Any ideas? I think we are really close. Thank you again.
    Best regards
    Vlad,

  15. #35
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    PHP Code:
     _configManager = new ConfigManager(new SingletonEnforcer(),xmlVar1); 
    PHP Code:
     public class ConfigManager extends EventDispatcher {                 
    private var 
    xmlVar1
    ~calmchess~

  16. #36
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Thank you so much for your responces. However, I have to leave for today. I will try to implement it and if I still will not b able to make I will get back here.
    Once again, I really appreciate your help. THANK YOU!
    Best regards
    Vlad,

  17. #37
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Calmchess, I tried to not bother you with this issue but after spending a time on numerous attempts to make it work I am giving up. Obviously, I need to read more about AS 3.0, however, I'd like to find out what I shoud be doing to make it right now.

    I have a Document class. I can get the Flashvars Value, but I fail to pass this string to the class needed.
    I get Flashvars with this line of code:
    Actionscript Code:
    _flashVars = stage.loaderInfo.parameters.xmlfile:

    I pass Flashvars to the class:
    Actionscript Code:
    var _config:ConfigManager = new ConfigManager(_flashVars);

    Below is the main-document class:
    Actionscript Code:
    package src.vladc {

        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
    Modified ConfigManager class below:

    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 {
            // 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;
            }
           
        }
       
    }

    What I do wrong? Thank you again.
    Last edited by vladc77; 06-01-2010 at 08:13 AM.
    Best regards
    Vlad,

  18. #38
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    does xmvar1 trace a value inside config manager you have things correct i don't see where you use xmlvar1 as part of the path to call the xml file..........you are very close I'd trace my values each step of the way and find where it fails.
    ~calmchess~

  19. #39
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    How can I trace it? I cannot publish it. I am getting errors - "1136: Incorrect number of arguments. Expected 2."
    Best regards
    Vlad,

  20. #40
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    I believe it is something related to SingletonEnforcer. The class is below.

    Actionscript Code:
    package com {
       
        class SingletonEnforcer {}
       
    }
    Best regards
    Vlad,

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