PDA

View Full Version : Calling Actionscript from Uscript



MagnusTheRed
05-09-2011, 09:42 AM
Hey, i'm reletively new to UDK and uscript, so i think i'm missing something really basic here. I've been over all the relevant tutorials etc and i can't seem to work out why my uscript functions can't call actionscript, and vice versa. My code is as follows:

class AoD_GFxMoviePlayer extends GFxMoviePlayer;

var AoDPlayerController OwningPlayer;
var ASValue RetVal;
var GFxObject RootMC, PauseMC;


function bool Start(optional bool StartPaused = false)
{
super.Start();
Advance(0);
}


function DisplayUpgradeMenu()
{
RenderTextureMode = RTM_AlphaComposite;
RenderTexture = none;
SetMovieInfo(SwfMovie'AoD_Scaleform.Example.300log o');
CallAS();
}

function CallAS()
{
OwningPlayer.ClientMessage("testing 1, 2, 3");
ActionScriptVoid("myDemoFunction");
}

function ShutThisMovieDown()
{
OwningPlayer.ClientMessage("Log Check to see if the function was called");
close();
}


defaultproperties
{
bPauseGameWhileActive=TRUE
bCaptureInput=true
bOnlyOwnerFocusable = true
}

With the function DisplayUpgradeMenu() having been called from another class.

The action script is:

_global.gfxExtensions = true;
_persfov = 25;
import flash.external.ExternalInterface;

var keyboardInput:Object = new Object();
Key.addListener(keyboardInput);

keyboardInput.onKeyDown = function() {
var keyPressed:Number = Key.getCode();
if(keyPressed == 81) {
ExternalInterface.call("ShutThisMovieDown");
} else if(keyPressed == 113) {
ExternalInterface.call("ShutThisMovieDown");
}
}

public function myDemoFunction():Void {
LogoExample.gotoAndPlay("On");
}

Obviously the relevant keyframe is labled 'On' etc etc.


The swf displays on the screen but won't play the movie, which is just a short animation, and pressing Q (key 113/81 depending on capital or lower case) doesn't shut down the movie either.

As far as i can see my code follows what is in all the tutorials/explanations on this topic, have i missed something really basic?

Charleon
05-09-2011, 11:34 AM
I think what you've missed is that ActionScriptVoid should be used with a GFxObject Reference, e.g say you have your code in the Root of the flash:

GFxObject RootMC;


function bool Start(optional bool StartPaused = false)
{
super.Start();
Advance(0);

RootMC = GetVariableObject("_root");
// or if you ahve it inside a movieclip in root:
// RootMC = GetVariableObject("_root.theobjectimtryingtoaccess_mc");
}

then you can do RootMC.ActionScriptVoid(...).
be vary that ActionScriptVoid tries to send in the parameters of the wrapping function, so if you would have put that in start it would try to send the optional bool, but I don't think it matters if you have 0 parameters on the AS side.

Matt Doyle
05-09-2011, 04:00 PM
You should not need to preface ActionScriptVoid with Root. It should be fine. If you fire off myDemoFunction() in ActionScript, does the movie animate properly?

As for the close() function, try this:

self.close();

MagnusTheRed
05-10-2011, 03:58 AM
Thanks alot for the quick reply's guys.

@Charleon - I had origionally tried that, hence the leftover: var GFxObject RootMC, PauseMC; at the top of the class, however it didn't seem to make a difference

@Matt - yes it works fine, I originally had the same swf file fired through kismet and it all worked fine, the problem has only popped up now that i'm doing it in uscript. Also i added the self.close();, however it's not reaching that function at all, since the OwningPlayer.ClientMessage("Log Check to see if the function was called"); line isn't logging to the screen.

Also to clarify the exact problem, when i trigger the function to call the actionscript, UDK crashes, however if i comment out the actionscript function call 'ActionScriptVoid("myDemoFunction");' Then the image appears on the screen, however obviously doesn't play the animation, nor does the 'ExternalInterface.call("ShutThisMovieDown");' line call when i press 'Q'

I also tried commenting out the code in the mydemofunction() actionscript file, and triggering the function still crashed UDK, so it seems to be something about the call itself.

Thanks again for the responses, any ideas as to what could be breaking it?



EDIT:

Just changed the main flash section to:

var keyboardInput:Object = new Object();
Key.addListener(keyboardInput);

keyboardInput.onKeyDown = function() {
var keyPressed:Number = Key.getCode();
if(keyPressed == 81) {
ExternalInterface.call("ShutThisMovieDown");
myDemoFunction();
} else if(keyPressed == 113) {
ExternalInterface.call("ShutThisMovieDown");
}
}

So that if i press 'Q' it should play the animation, however this doesn't work, since the LogoExample.gotoAndPlay("On") line is fine (worked when called from kismet), i'm assuming there is something wrong with my detection of the keybindings?

Matt Doyle
05-11-2011, 10:58 AM
Your code all looks exactly right. Not sure why you're having trouble. Hard to diagnose without seeing all your files for myself.

Have you tried adding a trace statement in your onKeyDown function?


var keyPressed:Number = Key.getCode();
trace("Key Pressed: " + keyPressed);

Just to make sure its working?

As for Unreal crashing, that could be a bad install maybe. It could be corrupted somehow. What version of UDK are you on?

Does this log message fire?


OwningPlayer.ClientMessage("testing 1, 2, 3");

Also...are you setting the SWF with this function?


function DisplayUpgradeMenu()
{
RenderTextureMode = RTM_AlphaComposite;
RenderTexture = none;
SetMovieInfo(SwfMovie'AoD_Scaleform.Example.300log o');
CallAS();
}

If so, why? Is the SWF something else to start with? Because when the SWF is loaded, it executes Start() before doing anything else. If it doesn't know what it is supposed to be when it does that, that could be a problem. Not sure how you're defining the SWF, as I don't see it defined in the default properties. How is the AoD_GFxMoviePlayer created in the first place?

MagnusTheRed
05-13-2011, 12:22 AM
I managed to isolate the problem in the action script to the fact that myDemoFunction is a public function, if i take the public declaration off it, then all of the action script will run fine inside flash. but is this going to make it inaccessible via uscript?

As for the Uscript, it is still crashing UDK when the swf is called. First of all, yes, OwningPlayer.ClientMessage("testing 1, 2, 3"); is logging to screen, so it is making it to that function, it's simply the ActionScriptVoid("myDemoFunction"); which is not working.

And yes, i am setting the SWF inside this function:


function DisplayUpgradeMenu()
{
RenderTextureMode = RTM_AlphaComposite;
RenderTexture = none;
SetMovieInfo(SwfMovie'AoD_Scaleform.Example.300log o');
CallAS();
}

The swf was never anything else to begin with, the actual code for calling the DisplayUpgrdaeMenu() funciton is in another class, which extends of playercontroller.uc


simulated function ShowUpgradeMenu()
{
if (WorldInfo.NetMode != NM_DedicatedServer)
{
if (InteractTarget.OwningPlayer == GetALocalPlayerController())
{
if(UpgradeMenu == none)
{
UpgradeMenu = new class'AoD_GFxMoviePlayer';
}
UpgradeMenu.OwningPlayer = self;
UpgradeMenu.DisplayUpgradeMenu();
}
}
}

That is the function which is calling it, should i be calling it differently? where else would i declare the SetMovieInfo?

Matt Doyle
05-13-2011, 10:49 AM
That could be the problem (crashing). I would declare the SWF in one of two ways:

Either in the default properties of the AoD_GFxMoviePlayer class:


defaultproperties
{
MovieInfo = SwfMovie'AoD_Scaleform.Example.300logo'
}

Or, in the class that calls it like so:


UpgradeMenu.MovieInfo = SwfMovie'AoD_Scaleform.Example.300logo';

In either case, your calling class should start the movie with this:


UpgradeMenu = new class'AoD_GFxMoviePlayer';
UpgradeMenu.MovieInfo = SwfMovie'AoD_Scaleform.Example.300logo'; // or declare the SWF in the defaultproperties of AoD_GFxMoviePlayer
UpgradeMenu.SetTimingMode(TM_Real);
UpgradeMenu.Start();

MagnusTheRed
05-17-2011, 09:29 PM
Hmmm, regardless of the way I call it or where i set the movie info I seem to be having the same error. I think im going to have a big reinstall of flash and UDK and see if that fixes the problem. Thanks for all your help!

MagnusTheRed
05-26-2011, 10:09 AM
Just for anyone else who has a similar problem, upgrading from CS3 to CS 5 fixed the problem, it all works now. No idea why.