Processing a PHP variable in AS3

I have looked in every book that I have on AS3 and cannot
come up with a solution to this, I hope that someone can help me.
I am receiveing a data string from a PHP --- mySQL connection
on my web server. The string is arriving in flash as I can trace it
and see the variables. If I do a trace on event.target.data I see
the following.
&numResult1=4&numResult2=14&numResult3=37&numResult4=70&numResult5=5&numResult6=3&doneLoad ing=true
This is exactly what I should be seeing based on my PHP code.
I am trying to assign the numResult numbers to a dynamic text
box, for instance numResult1 = 4, I would like to assign that 4 to
a dynamic text field on the Flash Stage. I have not figured out a
way to get the variable out of the string.
I keep getting undefined or a variety or other errors with
the different methods I try.
I have tried numerous ways using the URLVariables class but I
have had no luck. Use to be very simple in AS2, I could assign the
variable right to the dynamic text field in the properties panel,
not anymore.
Does anyone know how I can do this. People are doing it all
the time, it can't be that hard, is it?????
Just a good example as to how to break the variables out
would be really helpful. I have tried the FlashGods site and could
not figure there examples out, in fact the two I tried did not work
at all.
I would appreciate any help.... Thank you.
Mike

I have been trying to work this through for over a week, here
is the ActionScript Code;
AS
function getData(event:Event):void {
var myURLLoader:URLLoader = new URLLoader();
var myURLRequest:URLRequest = new URLRequest("polls2.php");
// Actually goes to a web site.
myURLLoader.dataFormat=URLLoaderDataFormat.TEXT;
myURLLoader.load(myURLRequest);
myURLLoader.addEventListener(Event.COMPLETE,
completeHandler);
function completeHandler(event:Event):void {
trace(myURLLoader.data);
var myURLVariables:URLVariables = new
URLVariables(myURLLoader.data);
gotoAndStop(2);
Here is what I get with the Trace Statement:
&numResult1=6&numResult2=6&numResult3=5&numResult4=9&numResult5=7&numResult6=1&doneLoading =true
Here is what I get when I try to set the URL variables.
Error: Error #2101: The String passed to
URLVariables.decode() must be a URL-encoded query string containing
name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at MethodInfo-2()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Now it sure looks to me that the string being passed is
name/value pairs.
I have tried every way that I can think of to capture this
data. I must be missing something simple.
Any ideas would be greatly appreciated.
Thanks for your help.
Mike

Similar Messages

  • Passing variables from AS3 to PHP

    Hi there
    I am having some trouble in passing variables from AS3 to PHP. I am using flash and php both in the same file [try.php].
    I've stuck with this for two days.. Here's what I have done. Please help!!!
    header.fla [Actionscript in the timeline]
    stop();
    import flash.events.Event;
    import flash.display.Sprite;
    import flash.net.*;
    var url:String = "http://localhost/0000/try.php";
    var req:URLRequest = new URLRequest(url);
    var loader:URLLoader = new URLLoader();
    var variables:URLVariables = new URLVariables();
    send_btn.addEventListener(MouseEvent.CLICK, sendForm);
    function sendForm(evt:MouseEvent):void
        // add the variables to our URLVariables
        variables.asd = "value";
        // send data via post
        req.method = URLRequestMethod.POST;
        req.data = variables;
        loader.dataFormat = URLLoaderDataFormat.TEXT;
        // add listener
        loader.addEventListener(Event.COMPLETE, onLoaded);
        loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        //send data
        loader.load(req);
    function onLoaded(evt:Event):void
        var result_data:String = String(loader.data);
        if (result_data)
            trace(result_data);
        else if (!result_data)
            trace("error");
    function ioErrorHandler(event:IOErrorEvent):void
        trace("ioErrorHandler: " + event);
    try.php
    <body>
    <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="563" height="280">
      <param name="movie" value="header.swf" />
      <param name="quality" value="high" />
      <param name="wmode" value="opaque" />
      <param name="swfversion" value="6.0.65.0" />
      <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
      <param name="expressinstall" value="../Scripts/expressInstall.swf" />
      <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="header.swf" width="563" height="280">
        <!--<![endif]-->
        <param name="quality" value="high" />
        <param name="wmode" value="opaque" />
        <param name="swfversion" value="6.0.65.0" />
        <param name="expressinstall" value="../Scripts/expressInstall.swf" />
        <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
        <div>
          <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
          <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
        </div>
        <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
    <?php
    if($_POST['asd'])
    echo "value of var1 is <b>".$_POST['asd']."</b>";
    else
    echo "bad luck";
    ?>
    </body>
    BIG THANKS!!

    the problem is nothing your showed.   did you see a security warning that you ignored?
    to test, if that's the problem go here and adjust your security settings:  http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.ht ml
    if that fails, upload your files to a server and confirm everything works.  then start working on your local configuration.

  • PHP variable scope bug in CT

    I have a page where I declare PHP variables which are then
    used inside an include file.
    When I try to edit the page in Contribute, I get a notice of
    "Variable undefined" in the include.
    This do work in Dreamweaver and it did work in Contribute in
    other projetcs I have done.
    Any suggestions?

    Hi Dont know if your still getting notifications on this but...
    Did you ever find an answer as I am having the same issue.
    I have tracked down why its not working but don't know how to stop it.
    In Dreamweaver it keeps the php include reference as code when it saves the file, where as Contribute seems to process the include and dump the output back to the page.
    This means that any common includes like headers and footers are no-longer included dynamically when the page loads as Contribute has embeded them when it created the page.
    This alsos mean if you have included a php file with common functions that you may use on your site this will never appear and any variables you declare wont exist.
    How rubbish is that!?
    If anyone can help with this issue it will be greatly appreciated.
    I'm hoping there is some simple Contribute comment I can put in to say "dont process this code - leave it alone!"
    Thanks

  • Parsing PHP Vars in AS3

    I'm pulling in vars from a PHP file into AS3, which im very new at, and having a few general and what i assume easy questions:
    first of all, my php looks like this:
    <?php
    $first="VARDATA";
    echo "v1=$first";
    ?>
    my question is, why can't i:  echo"$first"  
    i have to: echo "v1=$first"
    here's the actionscript pulling in the data, I assume there's a parsing issue perhaps??
    var myLoader:URLLoader = new URLLoader();
    myLoader.dataFormat = URLLoaderDataFormat.TEXT;
    var myRequest:URLRequest=new URLRequest("thefile.php");
        myLoader.load(myRequest);
        myLoader.addEventListener(Event.COMPLETE,onCompleteHandler);
        var newValue: String;
        function onCompleteHandler(e:Event):void{
        var newvariable: URLVariables = new URLVariables(e.target.data);
        newValue = newvariable.values;

    YOu can echo whatever you like, but chances are you don't want to quote the $first variable like you are doing.
    The URLVariables class reads the data in name/value pairs (name=value), which is why you want to send v1=VARDATA

  • Creating variables in AS3 that Captivate can read.

    I have a Flash project written in AS3 and I am colaborating with someone that is writing a Captivate training program.  The Flash program is a little game and I need to store a couple integers readable by Captivate.   I would like to just create the variables in AS3 and have them readable by the Captivate code (that I am not writting).
    If that's not possible I suppose I need to actually locate and update the varibles in Captivate (we decided on some variable names).
    user_pass  (integer, 0 means user is still trying and 1 means user passed)
    user_attempts ( I will store how many attempts the user made at the game)
    Thanks very much for any help.  I think she is pretty strong in her Captivate coding abilities, and I am only moderate in my Flash/AS3 abilities.
    Edit: I wanted to mention that the flash game was embedded into a slide in Captivate.

    In AS3 you can use the bracket notation...
    var trainOfUfo = "...hi earthling...";
    var handleBlade = this["train"+"Of" + "Ufo"];
    AS2 supports the eval() function, but it was done away with in AS3

  • Global variable in as3.0

    I am doing something with flash cs3,I need to use global
    variable in it ,but there is not global variable in as3.0,can
    anyone help me ,thanks forever!

    There is no global in AS3. But you can make values globally
    accessible by
    using static fields in classes. e.g.
    // MyClass.as
    package
    public class MyClass
    public static var globals = new Object();
    MyClass.globals["hello"] = "world"
    trace(MyClass.globals.hello);
    // and if you want to simulate something a little
    // closer to the AS2 _global object you can drop
    // this into a top level in your class path
    // global.as
    package
    public const global:Object = new Object();
    global["hello"] = "world";
    trace(global.world)

  • Autocomplete Declared PHP Variables in Dreamweaver

    Is there a way to autocomplete php variables that have been
    declared? For instance, whenever you type $ in a PHP code block, a
    pop up list would automatically come up with all the variables you
    have already declared. This would GREATLY speed up coding and help
    to insure coding accuracy.
    If there is a way to do this now, could someone please clue
    me in? I've searched and searched forums, help files, and google.
    If this is not available, where should I go to request this
    feature?
    Shanna

    jsteinmann wrote:
    > With asp.net missing, along with several other things
    discontinued, dreamweaver will have to cater to php developers in
    these kinds of ways.
    If you want Dreamweaver to add features posting this sort of
    comment in
    a user-to-user forum won't have the slightest impact on the
    direction
    that Dreamweaver actually takes. You need to make your views
    known by
    submitting feature requests through the official channel:
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
    Submitting requests doesn't guarantee that your ideas will be
    adopted in
    the next version or even the one after that, but it does get
    them on the
    development team's radar.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

  • Are there a dynamic way for evaluting variables in as3?

    Hi..!
    eval() is a usefull method or function in javascript.. Because we may define our variables via dynamic way..! There are following code is for understanding that how can define dynamic defining variables in javascript.. And Are there a dynamic way for evaluting variables in as3 like following javascript code?
    <script language="javascript1.2" type="text/javascript">
    var trainOfUfo = "...hi earthling...";
    var handleBlade = eval("train"+"Of" + "Ufo");
    alert(handleBlade);  //-- it appears in dialog box text field area "...hi earthling..."---
    </script>
    Gürkan Şahin
    Code Developer
    Turkey

    In AS3 you can use the bracket notation...
    var trainOfUfo = "...hi earthling...";
    var handleBlade = this["train"+"Of" + "Ufo"];
    AS2 supports the eval() function, but it was done away with in AS3

  • Captivate 5.5 variables in AS3

    Hi, i seem to be having a problem accessing the captivate 5.5 variables in AS3.
    I saw guides that tells people to do something like
    var myRoot:MovieClip = MovieClip(root);
    var mainmov:MovieClip = MovieClip(myRoot.parent.root);
    mainmov.rdcmndPause = 1;
    but i cant get it to work.

    Hello,
    What do you mean by 'playback': from the screenshot I deduct it is Previewing. Did you try to view in Web browser of after publishing already?
    Could you check the quality of the slides in the Properties, General region?
    Lilybiri

  • XSL and a php variable

    I am looking for a solution to a problem I am having with an
    XSL stylesheet and trying to use a php variable. The page I am
    working on is a page to display some information based on the
    graduation year of a class (I work at a school). For example last
    years graduating class of 2006.
    I have a statement in the XSL sheet that limits the shown
    data to only that class year
    <xsl:for-each
    select="school[class_of=&apos;2006&apos;]">
    I would like to replace that 2006 above with a php statment
    such as $classyear since on that page the data is to display the
    variable is already present, but I cannot get it to work. I have
    tried to place php in the XSL and also to change the extention etc
    and they all produce errors. I am assuming that XSL just can't use
    variables in it?
    Any help would be greatly appreciated. I would hate to have
    to duplicate that one XSL sheet for every class year.
    thanks
    chris

    David,
    thank you so much so far for you help, it does sounds like we
    are talking about the same thing. I think I am getting close.
    I do want to pass the value when the XSL sheet is embedded.
    I tried that and it seemed to not work, says the variable is
    not found (I am using the dreamweaver built in transform).
    I am just getting into the more complex XML stuff so I
    apologize for my lack of knowledege.
    I have pasted some of the code below, any idea what I am
    doing wrong?
    the page where it is embedded is
    http://www.nmhschool.org/news/test11.php
    php doc with the embed and include
    <?php
    $mm_xsl = new MM_XSLTransform();
    $mm_xsl->setXML("test11.xml");
    $mm_xsl->setXSL("test11.xsl");
    $mm_xsl->addParameter("yearXX", "2006");
    echo $mm_xsl->Transform();
    ?>
    http://www.nmhschool.org/news/test11.xsl
    is the XSL
    <xsl:for-each
    select="Report/GroupHeader2/GroupHeader2_1[q1.CnPrAl_Class_of =
    $yearXX]">
    <table width="100%" border="1" cellspacing="1"
    cellpadding="1">
    <tr> blah blah blah........
    http://www.nmhschool.org/news/test11.xml
    is the XML data

  • PHP Variable Capitalize

    Okay so I have a php variable, and I set it to "Home", then when I call it though I get a result of "home". How do I make the variable retain the capital H?

    MurraySummers wrote:
    No - actually we were both incorrect. The only condition is "isset($_GET['page']", and if true, the first option is executed and a lower-case value is returned; if false, the second.
    I think that's wrong. If the first condition was being executed then the OP would have the result "Home" returned NOT "home"
    He/She has obvioulsy got a link set up like .php?$foo=Home
    As the first condition IS met as you say and is correct the second condition is executed (met) as I say, the third is only returned if 1 and 2 are not met.
    Oh ok I see what your saying. Cross wires AGAIN we both agree that the ?> is being met
    I think half this stuff is a battle with the correct terminology aint it lol
    So this is being met:
    $page = (isset($_GET['page'])
    This is being return as the above is met
    ? strtolower($_GET['page'])
    This never gets a look in
    : 'Home');
    If you view the conditions as ? strtolower($_GET['page']) : 'Home');
    Then youre right I'm wrong.
    This is not a condition which I was taking into consideration.
    $page = (isset($_GET['page'])

  • Accessing PHP variables (especially _SESSION)

    Hi,
    since CaioToOn! suggested here that I should use $_SESSION and I need to do this anyway, I spent the last 1+ hours trying to figure out how to do that. Sadly, I could not really figure it out except that there seems to be an issue with the session ID and that it has to be passed along to the swf file.
    Can somebody please tell me how to read/write from/to PHP variables (not $_GET)?
    P.S.: Here a simple example code (test.php and then the testintro.fla AS code):
    <? session_start();
    $_SESSION["intro"] = 0;     // has the intro been played?
    ...     // code for including the swf
    ?>
    if(intro == 0)
         myclip.gotoAndPlay(2);   // play intro
         intro = 1;
    else
    { myclip.gotoAndPlay(24); }     // skip the intro and go straight to the end

    none of those reasons would require php to embed a swf.
    normally, with flash, you could use a session variable to pass data from html to the swf.  you set your session variable's data with a html form or something similar and then use flashvars to pass that info to your embedded swf(s).
    you can also pass html data to an embedded swf using javascript and the externalinterface class.

  • Is there a PHP variable that will fetch the TITLE of the file?

    I learned (thanks to David Powers) that you can use $_SERVER['PHP_SELF'] to refer to your current URL, which is useful in situations like putting a "Share on Facebook" button on your page.
    However, some of these social networking sites allow you to also put the Article Title in the same button, so I was wondering if there was a PHP variable I can use for *that*. This way, by specifying the title of the article in the aptly-named title tag of the page, I can put those "submit this page to" links as includes that don't need to be specifically-edited for each page.

    Create a variable for the title and use it in both places.
    <?php
    $title = 'Things you always wanted to know about...';
    ?>
    <title><?php echo $title; ?></title>
    // later on
    <?php echo $title; ?>
    Alternatively, if your page content is generated dynamically, you can store the title in the database.
    Another technique would be to base the title on the page name.
    $page = basename($_SERVER['SCRIPT_FILENAME'], '.php');
    $title = ucwords(str_replace('_', ' ', $page));
    That would store "About Us" in $title if the page is called about_us.php.

  • Search/Replace for/with php variable name

    Hi all.
    I have just updated from Dreamweaver 5 to 5.5 and now I am missing a very handy functionality.
    What I want to do is to replace all occurences of $a with $b.
    In Dreamweaver 5 that was very easy by using "Find and replace":
    Find in: All open documents
    Search: Sourcecode
    Find: $a
    Replace: $b
    Active options: Match case and Match whole word !!!!
    Now in Dreamweaver 5.5 the option "Match whole word" is automatically disabled as soon as I enter a $ (dollar) in the search field.
    I assume this has something to do with regular expressions but I do NOT check the option "Regular expression" in the search and replace dialog.
    Is this a bug?
    What are my options now.
    If I don't have the possibility to to tick "Match whole word" my search does also replace all occurrences of $abc and $answer etc. with $b.
    Thank you for your help

    samet2011 wrote:
    I have Dreamweaver 5 and 5.5 running parallel on my computer.
    I can confirm that the way I described and used to use is working on Dreamweaver 5.
    I was the person who informed Murray that Dreamweaver CS5 and CS5.5 both behave the same way. I have just checked as far back as CS3, and it also disables "Match whole word" when you enter a dollar sign in the Find field of the Find and Replace dialog box. In fact, that option is disabled whenever you enter any nonalphanumeric character (except an underscore) in that field. It's not limited to dollar signs.
    Why it's not disabled in your version of CS5 is a mystery.
    However, to solve your problem, you don't need either a regex or "Match whole word". Simply type the name of your PHP variable followed by a space into the Find field. Also add a space after the name of the variable you're using as the replacement.
    What "Match whole word" does under the hood is to use a regular expression to find a word break. As long as you leave a space between your variables and any following code, simply adding the space to your search will do the trick.
    However, if you have cases where a variable is followed by a comma, closing parenthesis, or some other character, you will need to use the following regex:
    Find: \$variable_name\b
    Replace: $new_name
    The \$ looks for a dollar sign. The variable_name matches the literal text of the variable name (replace it with the actual text you're looking for). The \b matches a word break in exactly the same way as "Match whole word".
    In the Replace field, $new_name is the literal name of the new variable.

  • PHP Variables unloading

    I have a lot of included files in my site. At the end of each
    included file,
    I close the sql, but would also like to close the variables
    used to produce
    the HTML.
    I'm having a hard time with my searching getting some
    relevant results. Can
    somebody help me here on what I"m looking for?
    TIA,
    Jon Parkhurst
    PriivaWeb
    http://priiva.net.

    On Thu 24 Aug 2006 04:36:46p, crash wrote in
    macromedia.dreamweaver.appdev:
    > I have a lot of included files in my site. At the end of
    each included
    > file, I close the sql, but would also like to close the
    variables used
    > to produce the HTML.
    >
    > I'm having a hard time with my searching getting some
    relevant
    > results. Can somebody help me here on what I"m looking
    for?
    I'm not sure I follow you here. Are you saying that you want
    to limit
    the scope of the PHP variables to the included file, so that
    in something
    like this:
    <?php
    include_once('fileA.inc');
    include_once('fileB.inc');
    include_once('fileC.inc');
    ?>
    you can have a variable, say $crashsVariable, in fileA.inc,
    fileB.inc and
    fileC.inc, and have it take on a separate value in each of
    them, but not
    affect any of the others?
    Without doing any experimentation... Using the
    include_once()s makes the
    include files, and thus all their code, part of the larger
    code block.
    AFAIK, the scope of a variable would be the calling file, so
    the answer
    would be no.
    The PHP docs[1] have this to say:
    The scope of a variable is the context within which it is
    defined.
    For the most part all PHP variables only have a single
    scope. This
    single scope spans included and required files as well.
    but go on to add:
    However, within user-defined functions a local function
    scope is
    introduced. Any variable used inside a function is by
    default limited
    to the local function scope.
    So if you use $crashsVariable within a function within the
    included file
    (or, for that matter, the main file), it's local in scope.
    Otherwise, a
    variable exists for the entire page.
    If you've spent the include file building a long string of
    text, which is
    eventually output as HTML:
    <?php
    $myvar = "<head>\n";
    $myvar .= "<title>$myDynamicTitle</title>\n";
    echo $myvar;
    ?>
    the only way I know would be to do something like
    $myvar = '';
    Hopefully David Powers or somebody who actually knows might
    check in.
    [1]
    http://www.php.net/variables.scope

Maybe you are looking for