Announcement

Collapse
No announcement yet.

Understanding ActionScriptSetFunction

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

  • replied
    Thanks @milerk for your post. Helped me a lot trying to figure out how to get my AS to compile

    Leave a comment:


  • replied
    to make it work with as3, the unrealscript part you do exactly the same,
    but in flash you make your class dynamic so you can add properties to it at runtime:

    Code:
    public dynamic class TestClass
    {
    }
    and later in code for example:
    Code:
    public function OnButtonClick(ev:ButtonEvent):void
    {
         if (this.CallbackFunc != null) this.CallbackFunc();
    }
    you dont even need to declare/define CallbackFunc, its a delegate added at runtime by unrealscript call
    took me some time to get to that, but it finally works even from few layers down

    Leave a comment:


  • replied
    I think ExternalInterface.call only looks for the function in the GFxMoviePlayer class used but not, say, in aggregated subwidgets which might be several "layers" down. My understanding of the ActionscriptSet stuff is (please correct me if I'm wrong), that you could setup/register this callback to specific GFxObjects. I just thought it would be cleaner than the ExternalInterface.call for my purpose.
    In the end, I have used a custom EventListener which works great.

    Leave a comment:


  • replied
    Never tried it myself.
    Didn't realise it was even an option.
    That being said, what is the benefit of this method over an external call?

    eg. In AS3:
    Code:
                // Pass Unrealscript the new mouse coordinates
                ExternalInterface.call("UpdateMousePosition", e.stageX, e.stageY);
    In UScript:
    Code:
    /**
     *     @param 2d coords of mouse from the movie file.
     */
    event UpdateMousePosition(float X, float Y)
    {
        MousePosition.X = X;
        MousePosition.Y = Y;
    }
    If you need delegates, you could still add them in UScript and never get any errors/warnings/issues.
    *shrug*

    Leave a comment:


  • replied
    Has anyone gotten this to work with AS3? I have tried quite a bit, but upon start, the flash ui just flickers like hell, is non-functional and Widgetinitialized is not called at all.

    Leave a comment:


  • replied
    I'm not questioning the functionality, I'm just curious as the why and how of this part - "using the delegate from the calling UnrealScript function" since that passed in delegate is never being referenced from anywhere.
    I couldn't tell you. I didn't write the backend of the integration, so I'm not sure what's going on there. I only know how to use it.

    Well... I forgot to mention I'm using FlashDevelop, which uses the stricter MTASC compiler.
    I see. Well, I haven't used MTASC in a long time. Perhaps there is some way to flag it to compile anyway?

    Leave a comment:


  • replied
    Well... I forgot to mention I'm using FlashDevelop, which uses the stricter MTASC compiler.

    Maybe I just hit a dead end

    Leave a comment:


  • replied
    The UnCodeX answers part of my question, you can pass in other parameters. But it doesn't tell me if you are allowed to pass in multiple delegate, which one it picks if you do, or what mystical magic fairy dust is being used to do anything with the delegate being passed into that function.

    I'm not questioning the functionality, I'm just curious as the why and how of this part - "using the delegate from the calling UnrealScript function" since that passed in delegate is never being referenced from anywhere.

    Leave a comment:


  • replied
    It does compile. It simply complains that the function doesn't exist in the log window when executed in Fx Media Player. But if you've followed the tutorial and not missed anything, then UnrealScript will fire when MyASFunction is called in ActionScript.

    The tutorial is fully tested and confirmed working.

    Leave a comment:


  • replied
    Originally posted by Matt Doyle View Post
    Finally, in ActionScript, call the "MyASFunction" somehow.
    Code:
    // MyASFunction() does not actually exist in ActionScript.
    // Calling it here will instead execute the DoThis() function
    // found in UnrealScript.
    
    MyASFunction(true);

    But if it doesn't exist... it does not compile!

    Code:
    MyCoolMenu.as:149: characters 2-14 : type error Unknown class MyASFunction
    And if I declare it, the UnrealScript function isn't being executed.

    Leave a comment:


  • replied
    Here's the UnCodeX entry for the function:

    http://files.arbi.trari.us/Doc/gfxui...ptSetFunction-

    Leave a comment:


  • replied
    Maybe I'm missing something here but from a readability standpoint it's rather confusing to have ActionScriptSetFunction magically use the containing function's delegate. Seems like it would be preferable to have it take 3 arguments - the _global reference, the member name, and a reference to the delegate.

    Can functions that call ActionScriptSetFunction have arguments other than the delegate? What happens if you pass in 2 delegates?

    Leave a comment:


  • started a topic Understanding ActionScriptSetFunction

    Understanding ActionScriptSetFunction

    ActionScriptSetFunction allows you to execute an UnrealScript function when an ActionScript function is called in the Flash file.

    Example: In our hypothetical Flash file, we call a function in ActionScript called "MyASFunction()", but the actual function does not exist in ActionScript, and we want to instead fire off an UnrealScript function called "DoThis()" whenever this function is called on in the Flash file.

    Uses: This has many uses. One good use would be when you are sharing the same Flash file between many views, but want each view to handle a specific situation differently. You can then write a DoThis() function for each view in UnrealScript that does something different, without making a unique Flash file for each view. And thus, any time MyASFunction() gets called in the shared Flash file, it will execute a unique DoThis() function in UnrealScript depending upon which view you are on.

    Step 1

    Define the delegate.

    Code:
    delegate int MyDelegate(bool bTrue);
    Step 2

    Create the DoThis() function in UnrealScript. It's parameters and return type must match the delegate definition from step 1. This is the function that will be executed, whenever MyASFunction() is called in ActionScript.

    Code:
    function int DoThis(bool bTrue)
    {
        local int myNum;
    
        myNum = 5;
        `log("Do this UnrealScript function? " @ bTrue);
        return myNum;
    }
    Step 3

    Next, create the UnrealScript function that does the swapping magic. This function expects the delegate we wrote in steps 1 & 2 as a parameter. It then caches a refernce to _global, which encompasses the entire movie, including _root. Then, it uses ActionScriptSetFunction to specify that any time MyASFunction() is called in the Flash file, to instead execute the delegate we passed it, in this case - DoThis().

    Code:
    function SetMyDelegate( delegate<MyDelegate> InDelegate)
    {
        local GFxObject _global;
        _global = GetVariableObject("_global");
        ActionScriptSetFunction(_global, "MyASFunction");
    }
    Step 4

    Now we simply need to execute the SetMyDelegate function, and pass it the DoThis() function.

    Code:
    SetMyDelegate(none); // clear it first
    SetMyDelegate(DoThis);
    Step 5

    Finally, in ActionScript, call the "MyASFunction" somehow.

    ActionScript 2.0

    Code:
    // MyASFunction() does not actually exist in ActionScript.
    // Calling it here will instead execute the DoThis() function
    // found in UnrealScript.
    
    MyASFunction(true);
    The result should be that, whenever MyASFunction() is called in the Flash file, the Unreal log will print out:
    Code:
    Do this UnrealScript function? True
Working...
X