howto create a session variable in flash/actionscript

I have an .fla with various actionscript 3 modules. I'm used to jsp and there is a concept of session variables. actionscript also appears to have session variables, but when I try to set one using:

SessionVar.Set("%navButton%", "about");

I get the error: 1120: Acccess of undefined property SessionVar.

What am I doing wrong?
LVL 1
MarkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CyanBlueCommented:
There is no such thing as a session variable in ActionScript...  

Maybe you can explain what you are trying to do and we can help you better...

CyanBlue
0
MarkAuthor Commented:
yes, I just figured that out. I was looking at some other post that had the work actionscript in it. Wrong.

In doing more research, I find I want a global variable which apparently must be defined using a new class, e.g.:

package com.greenethumb.utils
{
    public class GlobalVarContainer
    {
        public static var vars:Object = {};
    }
}

Now, I have just been adding AS code to event, etc. I have not had need to create any new classes. I don't know how to do this in AS3. If you could help me get going, I'm sure I could reference the variables from there. First of all, where do I create such a "package"?
0
MarkAuthor Commented:
On the other hand, if that idea is too complex, ... I have a movieclip actionscript that executes whenever any of 4 buttons is clicked. Is there a way of know which button triggered the clip?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

MarkAuthor Commented:
Here's what I've tried so far. I created an actionscript file, buffaloGlobals.as in the com folder of my flash root. It contains the following:

package com.buffaloGlobals
{
    public class GlobalVarContainer
    {
        public static var vars:Object = {};
    }
}

I then put the following in the place where I want to put something in to my global container:

import com.buffaloGlobals;
GlobalVarContainer.vars.groupingID  = 1;

This gives me the error: Access of undefined property GlobalVarContainer

I should point out that I am trying to follow the instruction in: http://greenethumb.com/article/11/global-variables-in-as3
0
DeasilCommented:
Hi there.  If you want to be able to add properties to a class on the fly, which can be useful in a case like this, then your class needs to be dynamic. So:

package com.buffaloGlobals
{
    public dynamic class GlobalVarContainer
    {
        ...
    }
}

Will allow yout to add whatever you like to GlobalVarContainer so you can use it as a place to store your 'session variables'.  You need to be careful using this kind of thing though - in general don't do it because of course the compiler will stop checking the validity of your property names.  Also note that you can only add public properties and methods to a dynamic class!

Hope this helps.
0
MarkAuthor Commented:
I've changed the .as file as you've recommended in 28667897. It is now:

package com.buffaloGlobals
{
    public dynamic class GlobalVarContainer
    {
        public static var vars:Object = {};
    }
}

The action script contents are the same:

import com.buffaloGlobals.GlobalVarContainer;
GlobalVarContainer.vars.groupingID  = 1;

Now I get the compile error:

1172: Definition com.buffaloGlobals:GlobalVarContainer could not be found.
0
CyanBlueCommented:
How did the session variable question become something of a class question???  :D

jmarkfoley...  Can you upload the tester file???  It's fine if you want to close this topic and concentrate on the other topic at the AS.org...  Up to you...

CyanBlue
0
MarkAuthor Commented:
I'm new to actionscript. All I'm trying to do is create a global storage place of some kind. The code I've posted is just something I got off the web. My needs are simple: When the user clicks a button. I want to set a variable accessible by other actions that get run in the timeline. That's it. I have AS event handlers triggered by button clicks. I'd like to have that event handler set a variable so that other actions in the timeline know which button was pressed.

That's what I need. So far, my experimentation with this public package isn't working. In fact, it could be simpler than the example I've been trying. I just need a single integer or string with a variable name. Pseudo coding it in VB syntax I'd say:

public myButtonClick as String
:
myButtonClick = "gallery1"
:
if myButtonClick = "gallery1" then ...

that's it. That's all I need. How do I do that in AS?
0
CyanBlueCommented:
Here is the quickest example I can come up with...

CyanBlue
GlobalVars.zip
0
MarkAuthor Commented:
I found the problem. The problem was in the whole folder structure. As I mentioned in my 28651900 post, I created the file buffaloGlobals.as in the com folder as:

package com.buffaloGlobals
{
    public dynamic class GlobalVarContainer
    {
        public static var vars:Object = {};
    }
}

I then put the following lines in my action script:

import com.buffaloGlobals.GlobalVarContainer;
GlobalVarContainer.vars.groupingID  = 1;

That gave me an error, as I stated. BUT, when I changed the file name from buffaloGlobals.as to GlobalVarContainer.as and put that in the folder: com/buffaloGlobals/ it started working.

This was all a matter of monkey-at-the-typewriter experimentation. I have no real idea why this works from the formal language definition point of view. If someone could give me an explanation, or point me to an authoratative link explaining the correlation between class/package and directory hierarchy, I would be most grateful and award points.
0
DeasilCommented:
Hi there again,

Sorry for slow replies - been up the wall last couple of days.

Basically you need to make sure that the class name you define in your .as file corresponds exactly to the name of the class itself (case sensitive).  Your package name must correspond to the folder structure - because this is working for you, my guess is that you have already figured this out!  But for the sake of completeness, if you are using the Flash IDE the best way forward is probably to set the global classpath for the application to point at the root of where you want to store your code ('com' in your example).  The global classpath is accessed in the IDE from Edit/Preferences select ActionScript from the sidebar menu, click ActionScript 3 settings,  (Note that these settings can be overriden at the file level - when you have an .fla file open, you can change the settings at the file level - File/Publish Settings select 'Flash' tab then settings next to the Actionscript dropdown.


Now having said all of this and explained it, I have to say that even as a lover of all things Flash for many years, the way in which this works is pretty abstruse, and causes many many problems for even experienced programmers new to Flash - the good news is that although frustrating at first, once cracked, it does make sense.

My advice would be first to dump everything for five minutes and actually work through this tutorial, after which it should all start to click into place.

http://www.actionscript.org/resources/articles/698/2/Make-your-own-reusable-classes-using-Flash-and-AS3/Page1.html

Best of luck!!

D
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkAuthor Commented:
OK, thanks! That is all very useful!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.