Variable in actionscript
I currently use a text document to send dynamic text and
other variables to the .swf. I am now trying to use a variable
defined in the text document to complete the actionscript below,
but I can't quite figure it out. The line in the text document
looks like &howmanyevents=11 and I'd like the actionscript to
stop the movie if the variable equals eleven.
if(_root.howmanyevents == 11) {
stop();
any suggestions?
oh. when flash reads a text or xml file everything is a
string. even things like 11 that look like a number. to remedy, use
the Number() function to convert _root.howmanyevents to a number:
if(Number(_root.howmanyevents) == 11){
stop();
}
Similar Messages
-
Inserting text from a variable in actionscript
what is it called when you insert text from a variable in actionscript?
Your question is not clear. There is no specific name for the process of inserting text from a variable that I am aware of.
If you have a dynamic textfield that you have assigned an instance name to, let's say you named it "tField", then to assign a variable called "aVar" to that textfield you would use:
tField.text = aVar; -
Global variable in ActionScript 3:
Hi Everyone,
I'm looking at a short example on
http://www.greenethumb.com/article/11/global-variables-in-as3
in which the author creates a separate package as such:
package com.greenethumb.utils
public class GlobalVarContainer
public static var vars:Object = [];
The problem is that when I do this (when I add that snip to
the top of my single .as file), I get the following error:
"5006: An ActionScript file can not have more than one
externally visible definition:
com.greenethumb.utils.GlobalVarContainer, Untitled314"
I've already got another package {...} on that same .as file.
If I just stick this:
public class GlobalVarContainer
public static var vars:Object = [];
...then I get the somewhat similar error message:
5006: An ActionScript file can not have more than one
externally visible definition: GlobalVarContainer, Untitled314
I don't know where to put this.Have your global AS script in its own .AS file then import it accordingly.
I have a sample here: http://www.smithmediafusion.com/blog/?p=436 -
Post Variables Using Actionscript
Hi,
I have seen on the docs that we could write HTTPService in
Actionscript method. I have completed the entire section based on
the description of the method defined on the doc, but I am having
some issues defining the variables to pass to the actual service
(mx:request as in MXML).
I need to know the actual variable that gets passed to the
service, because I would like to reuse the information returned
from the service for further edits. Since this information is not
stored in the XML, I wonder if anyone can tell me what is wrong
with the syntax below? Currently, all I get is this error:
TypeError: Error #1009: Cannot access a property or method of
a null object reference.
Anything is appreciated."alice_data" <[email protected]> wrote in
message
news:ge9nf1$1ai$[email protected]..
> Hi, Amy:
>
> Sorry, but I think I am getting a little confused at
this point. I have
> removed
> var loader:URLLoader = new URLLoader();
> loader.addEventListener(Event.COMPLETE,
function(event:Event):void {
> trace("finished sending and loading: "+ loader.data);
> });
> loader.load(request);
> and ran the code again and received the same error as
before.
>
> Part of the problems with the error I have been getting
is that I have
> not
> defined my parameters correctly, but again I tried to
take the parameter
> definition from the following line, it tells me I need
one argument:
> <mx:Button
> label="Submit" id="mySubmitButton"
click="useHttpService()"/>. What should
> I
> put in the parenthesis?
>
> The doc I referred to is at
>
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?co
>
ntext=LiveDocs_Book_Parts&file=dataservices_099_15.html, but I
think my
> main
> problem here is that I am not sure how to define the
variables and pass it
> to
> the actual service and have the variables be handled
internally through
> Actionscript. Or, is what I trying to accomplish here
not possible at all?
Try changing this:
private var request:HTTPService;
to
private var request: URLRequest;
I still think you're getting a lot of warnings you're
ignoring (check the
problems tab). You should have gotten a duplicate variable
definition for
what you had.
What you're trying to accomplish is possible, but you DO need
to pay
attention to the warnings and errors Flex is trying to tell
you about. They
are your friend. -
Need help with setting a variable using actionscript
So I am trying to import in XML and this is working fine, But
once in flash I need to reference this variable in a later script.
Here is what I got.
function loadXML(loaded) {
if (loaded) {
/////this is the variable, which is working, it pulls the
info from the xml document properly.
var node1 =
this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
////another variable, etc...
var node2 =
this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
/////when traced it outputs the proper value.
trace(node1);
////////does not work here though.
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("co.xml");
var latmin = 37;
var latmax = 41;
var lonmin = -109;
var lonmax = -102;
this.geoPlotter_gp.setRange(latmin, latmax, lonmin, lonmax);
this.geoPlotter_gp.setNodeSymbol("geoPloterNodeSymbol");
this.geoPlotter_gp.addNode(40.48, -107);
////////////////This is where I need to now use the variables
defined above//////////////
this.geoPlotter_gp.addNode(node1);// Boulder
this.geoPlotter_gp.addNode(node2);// Denver
/////any ideas all? I am sure this is something simple...I am
just overlooking something.when you prefix a variable using var within a function,
you're making it local to that function. ie, node1 and node2 are
undefined outside loadXML().
to remedy, don't prefix with var. -
Request variables in Actionscript
i am building an application which will send parameters to the server.
we can send parameters through MXML using the <mx:Request> tag
is it possible to send parameters using actionscript ?could you give me an example..
my code looks like this..
internal
const DATAPROCESSOR_URL:String=http://localhost/FlexApp/DataProcessor.aspx;
_httpService =new HTTPService(null,null);_httpService.url = DATAPROCESSOR_URL;
_httpService.resultFormat =
"e4x";_httpService.useProxy =
false;_httpService.addEventListener(FaultEvent.FAULT,faultHandler);
_httpService.addEventListener(ResultEvent.RESULT, fillHandler);
_httpService.send(); -
Variable to track position in timeline
Hi guys, I am trying to create a variable in Actionscript 2 that will record the position in the timeline, so Flash knows the user's last position on the timeline.
The first line in the mc is:
var portfoliostate;
On frame 20 of the timeline, I have the following actionscript:
portfoliostate = "1_portfolio";
When a button is clicked, I want Flash to recognise if the user has been on frame 20 or not. The code on the button is:
this.onRelease = function() {
if (portfoliostate="1_portfolio") {
_root.gotoAndStop(90);
else {
_root.gotoAndStop(80);
However it does not seem to be working. I am implementing this correctly?
Many thanksYou need to use == when comparing, = when assigning
if (portfoliostate=="1_portfolio") { -
I am confused about what seems, on the surface, to be a huge
limitation of variables in ActionScript. I'm looking at the
following statement from documentation on creating variables:
"If a variable is declared in the FLA (instead of in an
external file), it works only for the frame where the variable is
declared. Only the frame code for that frame is scanned, so the
second frame would not recognize the variable if it was
referenced."
So this means that there's no way to store a value in a
variable and use it later in the movie, unless I create a separate
code file? That seems ridiculous. Let's say I want someone to type
in their name at the beginning of a movie; I can't store that value
in a variable and recall it later in the movie to address the
person by name? I can't possibly imagine that we would be forced to
do everything in external files just to have a variable that
actually stores something for longer than a frame. Can anyone set
me straight on this?You shouldn't flail around with _root, this, and whatever
else. You should develop a strategy for making sure variables are
where they need to be. I'm guessing it isn't your copy of Flash. :)
If it is a variable that everything needs, most likely a
_global variable would be a good choice. If you are keeping it
within this object or that movie clip, but can't find it when
needed, use the Debug–>List variables and it will show you
where everything is.
It sometimes does get tricky when trying to combine
Actionscript with timeline stuff. Personally I try and limit the
amount of playhead jumping around within my files. If I do run into
a problem, the best approach I've found is to set aside my current
project and try and develop the simplest model of the problem. Then
I can see how Flash works and how I can get what I need. In the
end, regardless of what the documentation says or how I want it to
work, Flash does what it does.
I'm sure they are trying to tell us something important, but
I don't know what it is from those sentences. Perhaps that if a
variable is defined within an object, like a movieclip and if that
movieclip doesn't exist at a later frame, then you won't be able to
get the variable? I really don't know. -
Loading Variables from ASP into Flash
I can find plenty of tutorials detailing how to load
variables from a defined asp page into Flash, but here's my
dilemma...
I have an asp page that is reading a URL with a unique
identifier in it (www.sampleURL.com?id=123456), and then turns the
id number from the URL into a variable. On the same page then, sits
my swf where I need to use LoadVars to pull in that ASP variable
via Actionscript. If I don't have a static asp page to pull the
variables in from and I want to pass the variable within the same
asp page the swf is located on, how do I do it? Many thanks in
advance..."bonzomn65" <[email protected]> wrote in
message
news:ej0630$pjh$[email protected]..
>I can find plenty of tutorials detailing how to load
variables from a
>defined
> asp page into Flash, but here's my dilemma...
>
> I have an asp page that is reading a URL with a unique
identifier in it
> (www.sampleURL.com?id=123456), and then turns the id
number from the URL
> into a
> variable. On the same page then, sits my swf where I
need to use LoadVars
> to
> pull in that ASP variable via Actionscript. If I don't
have a static asp
> page
> to pull the variables in from and I want to pass the
variable within the
> same
> asp page the swf is located on, how do I do it? Many
thanks in advance...
>
You don't need LoadVars for this at all. You can just pass
the variable to
your Flash movie by specifying a query string when you are
calling the
movie.
If you are using the straight object, embed method then it
would look
something like this:
<param name="movie" value="movie.swf?id=11111">
<embed src="movie.swf?id=11111" ... >
If you are using the ActiveContent JavaScript for your movie
then you just
leave off the .swf... so
"name", "movie?id=11111"
Then, in flash you can access the value of id from the _root,
like
var idInFlash:Number = _root.id;
Of course in the above example you would replace 11111 with
the proper
syntax for printing a variable's value in ASP. -
Variable problems local and global score
Hi i'm having problem of writing a value to a global variable
in a function and using this variable affterwards. My problems is
the following i have a firstProduct variable that is initialized as
global at the begining of my code and the i have an XML on load
function where i should take the first child and write it to his
variable and use it afterwards for passing it as a variable to PHP
but this is irrelevant, however when im trying to trace im getting
undefined any suggestions ?? here is the codewhen i trace the variable inside the function on load it
writes it but when i try to access it outside it is undefined im
really frustrated, how the heck i assing values to variables in
actionscript where i can access them from any frame that i want. do
u have any suggesstions? -
Help needed in making a login screen
hi all,
i need to make a login screen in flash in which a user enters
a password and username and both are checked from an xml file. i
need your help in making it. could anyone redirect me to some
tutorial or if anyone can post the code here, i would really be
grateful to you. thanks,
gauravFirst you need to load the xml file that contains the list of
user names and passwords into variables using actionscript.
Use this tutorial.
http://www.actionscript.org/tutorials/intermediate/XML/index.shtml
Then compare the value entered by the user with the list of
usernames and passwords.
But be aware:
1>All the processing happens on the client machine
2>Extremely insecure if you are after a secure login.
3>and when you update the XML file it won't necessarily
take effect immediately on all the user's machines as they may be
using a cached version of it.
Ideal method is to use server side validation script using
asp, asp.net, jsp or php. -
This is what I want to do. I want to take an XML file (which
is produced by a HTTPService request to a PHP file). Take the data
in the XML file and then place it in textboxes within a Flex Form.
Is this possible?
If there is some way that I can covert the XML data from the
HTTPService to variables in actionscript and the flex project that
would be even better.I found it.
http://blog.flexexamples.com/2007/09/19/converting-xml-to-objects-using-the-flex-httpservi ce-mxml-tag/ -
Bringing dynamically created controls into scope
Normally I can bring controls into scope in a function with
the line
var myControl = myControl;
where myControl is the name of the control.
If I dynamically create controls (called say cbx1, cbx7 etc.
where the
numbers are all different, but not necessarily contiguous)
and save
their names in myArray, then myArray[0] will contain the name
of one of
my new controls.
How can I bring this control into scope in my function?
And is there a way to create, read and change variable
variables in
ActionScript?
Dougcreate an array within your function that's local to your
function, if that's what you want. what's the purpose,
though? -
Hoe to acess the the session variable in actionscript?
Yes..You are right.
Session variables that lives on the server is accessible in
this way in .java file -
FlexSession flexSession = FlexContext.getFlexSession();
String username =
flexSession.getAttribute("userName").toString();
But , what if I want to access this session variable in my
actionscript file.
I tried to import flex.messaging.FlexSession in .as file but
it does not allow me to do so. -
Code hints across the timeline
Hi all,
If I define a variable in the first frame of my flash timeline (strongly typed).
var strMyString:String = "My String";
then stop the playhead on the 10th frame and access my variable in actionscript, I lose code hints.
stop();
strMyString.
Is it possible to have code hints available across the whole timeline or are they limited to the frame in which the variable was declared?
Many thanks..
Simon.You have to follow naming procedure for variables for proper coding hint.
In frame 1 itself if you type strMyString. nothing happens.
For a check I have typed strMyString_txt. in frame 10 then code hint appeared.
I hope I have succeed in explaining what I meant for proper naming convention.
Maybe you are looking for
-
What is the best display to replace a 15" matt MacBook Pro?
Hi everyone this is my first post. I have a dilemma that I need assistance with. I have plans on buying the new Mac Book Pro after two happy years with my current 2.33 GHZ *15" matt* version. However, as most of you will be aware I won't be able to b
-
Hi Gurus, I am working in CRM 4.0 Channel Management. I want to change only the name of the TAB, e.g. in the application Opportunity CRMD_ BUS2000111 the TAB name Attachments - field Group OPP_DOCUMENTS and event OPP_HD_DOCUMENTS. We only want to cha
-
AP_SUPPLIER_SITES_ALL- id explaination
Can someone please explain the following 4 id's individually on the AP_SUPPLIER_SITES_ALL table? Are they needed? Where do I get them? Is there a parameter's table I am not seeing? Thanks. SUPPLIER_SITES TOLERANCE_ID LOCATION_ID PARTY_SITE_ID SERVICE
-
Hi, Client's requirement is, Purchase department will create a request for Down Payment using prerequisite-47. And Down payment is posted through F-48. My problem is I am able to create the proceed upto F-48. After this how to print this cheque? Are
-
Email Completed Form, Not Data
Hello, I have created a form in designer with a "submit by email" button. It works perfectly as it should. What I would like to do is have the completed from sent back to me instead of the XML. Is this possible? The users are filling out the form as