Announcement

Collapse
No announcement yet.

[SOLVED] Invoke ActionScript function not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Invoke ActionScript function not working

    Hi!

    I'm making a map using scaleform. The only function of the map is to show the actual position of the current player. For that, I have edited the DefaultInput.ini file and add a .Binding(Name="M", command="ShowMyMap")

    In my gameinfo class I added

    Code:
    exec function ShowMyMap(){
      toggleMyMap();
    }
    Because my gameinfo class extends from UTDeathMatch, I can't use the ActionScriptVoid function, so what I did was:

    Code:
    var GFxMoviePlayer MapMenu;
    var vector pos;
    
    function toggleMyMap(){
       local array<ASValue> params;
    
       if (MapMenu !=none && MapMenu.bMovieIsOpen)
           MapMenu.Close();
       else{
           MapMenu = new class'GFxMoviePlayer';
           MapMenu = SwfMovie'UIs.GFX.map';
           [...] //more stuff to initialize the flash movie
           if(MapMenu.Start()){
               getPos(); //a function to get player current coordinates
               params.Add(2); //without this, the array always gave me error.
               params[0].Type = AS_Number;
               params[0].n = pos.x;
               params[1].Type = AS_Number;
               params[1].n = pos.y;
               MapMenu.Invoke("position",params);
           }
           else[...] //if everything fails...
    }
    In my flash file, there's a function called "position" wich receives two Number parameters, and with them it puts a point at the correct coordinates. I have a layer called "Posicion" who has an instance of a graphic object (playerPos) called "pointer".

    ActionScript code:
    Code:
    function position(posx:Number,posy:Number):Bool
    {
       pointer._x=posx;
       pointer._y=posy;
       return TRUE;
    }
    So, when I press M on my keyboard, the map appears on the screen, and if I press it again, it desappears. That works correctly. But it doesn't show the player position. I added an ASValue varible to get the return of the function and invoke always returns "false" It looks like the function is never called.

    ┬┐Any idea why is this happening?

    If there's a misconception in my code just tell me.

    Thanks

    #2
    I would advice you to use "ActionScriptVoid" instead of "Invoke", as i never really got the Invoke to work. using ActionScriptVoid sends in the parameters of the wrapping function meaning if you did:

    function SetMapPosition(int x, int y)
    {
    MapMenu.ActionScriptVoid("position");
    }

    and instead of MapMenu.Invoke("position",params);
    just call: SetMapPosition(pos.x, pos.y);

    also I don't know if you can get a returnvalue from Actionscript using Unrealcode, for that I think you might have to import flash.external.Externalinterface and do:

    ExternalInterface.call("MethodNameInUnrealScript", param1, param2......);

    the MethodNameInUnrealScript is the function name declared in the unrealscriptdocument wrapping tha flash

    Comment


      #3
      That was my first idea, but the ActionScriptVoid function is protected and I can't use it that way. I can use it only from a GFxMoviePlayer extended class (and it's not my case since I need an exec function)

      Comment


        #4
        Code:
        local ASValue Retval;
        Retval.Type = AS_Boolean;
        Retval = MapMenu.Invoke("position",params);
        `log("Retval: " @ Retval.b);

        Comment


          #5
          That's what I did to see what was happening, and Retval.b is always false.

          Comment


            #6
            Hmm. Works for me.

            https://udn.epicgames.com/Three/Scal...0_UnrealScript

            Comment


              #7
              I cannot access to the link (it requires user and password). When I call the Invoke function the same way you have posted it always returns false to Retval.b and nothing happens. There might be a problem with my flash file?

              Comment


                #8
                sorry - just remove the s in https.

                Comment


                  #9
                  I followed that tutorial, and is in the invoke function where I get stuck. So, you're telling me that it should work because everything is fine but, for any reason, it's not doing it, right? I hate when that happens...

                  Comment


                    #10
                    I'm saying it should work, because I tested it on my end, and I got the correct results. I couldn't say why it isn't working for you beyond that.

                    Maybe it is because you're doing all this from your game info class, instead of in a class that extends GFxMoviePlayer. Is there some reason you don't want to do that?

                    Try this maybe:

                    first, cache the _root of MapMenu.

                    Code:
                    var GFxObject RootMC;
                    RootMC = MapMenu.GetVariableObject("_root");
                    Then try to run invoke like this:
                    Code:
                    MapMenu.RootMC.Invoke("position", params);
                    or perhaps just try:

                    Code:
                    MapMenu.Invoke("_root.position", params);

                    Comment


                      #11
                      Because the exec functions can not be placed in a GFxMoviePlayer extended class.

                      But I guess I should create another class extended from GFxMoviePlayer, put all my code there (using the ActionScriptVoid function) and call it from my gameinfo class. Something like:
                      Code:
                      var MyGFxClass movie;
                      
                      exec function ShowMyMap(){
                          movie.GetThisInitialize();
                      }
                      And in MyGFxClass, wich extends from GFxMoviePlayer, do all the stuff about initialize the swf file, calculate the player position, and call ActionScriptVoid, right? I'll give it a try, fight against it for a while, and tomorrow I'll post the result.

                      Meanwhile, if you have an idea of why it's failing, I'll glad to read it!

                      Anyway, thank you very much!

                      Comment


                        #12
                        Try this maybe:

                        first, cache the _root of MapMenu.
                        Code:
                        var GFxObject RootMC;
                        RootMC = MapMenu.GetVariableObject("_root");
                        Then try to run invoke like this:

                        Code:
                        MapMenu.RootMC.Invoke("position", params);
                        or perhaps just try:

                        Code:
                        MapMenu.Invoke("_root.position", params);

                        Comment


                          #13
                          I create a new GFxMoviePlayer extended class (LsMap) so I can use the ActionScriptVoid function. I create a new object of this class from my exec function and call a method from the LsMap class wich handles everything. The result is the same: my map shows/hide correct, but the function is not called.

                          I'm pretty sure the problem is not the unreal script code (as far as it seems correct) but in my flash file, because I can get the _root (with the GetVaribleObject("_root") function) but none of the other layers I have.

                          Code:
                          RootMC = MapMenu.GetVariableObject("_root");
                          something = RootMC.GetObject("Posicion"); //this is always 'none', but there's a "Posicion" layer in the root of my flash file.
                          @Matt_doyle I tried that but it doesn't work. The invoke function still returns false.

                          Comment


                            #14
                            Originally posted by Beakman View Post
                            I create a new GFxMoviePlayer extended class (LsMap) so I can use the ActionScriptVoid function. I create a new object of this class from my exec function and call a method from the LsMap class wich handles everything. The result is the same: my map shows/hide correct, but the function is not called.

                            I'm pretty sure the problem is not the unreal script code (as far as it seems correct) but in my flash file, because I can get the _root (with the GetVaribleObject("_root") function) but none of the other layers I have.

                            Code:
                            RootMC = MapMenu.GetVariableObject("_root");
                            something = RootMC.GetObject("Posicion"); //this is always 'none', but there's a "Posicion" layer in the root of my flash file.
                            @Matt_doyle I tried that but it doesn't work. The invoke function still returns false.
                            By GetObject() you get an OBJECT form the scene, not a Layer, e.g you ahve a helathbar named health_mc then you should write GetObject("health_mc");

                            Comment


                              #15
                              By GetObject() you get an OBJECT form the scene, not a Layer, e.g you ahve a helathbar named health_mc then you should write GetObject("health_mc");
                              What a misconception by my side! Anyway, I have tried that, but it returns 'none'. I tried to follow some tutorials I found googling for a while, but all of them are using FSCommands and CLICK objects. The first one is not recommended for use in production, so I prefer to learn how to use uscript/ascript properly. I don't use the second one because I want to use my own objects, functions, etc.

                              Thanks for the help anyway

                              Comment

                              Working...
                              X