Announcement

Collapse
No announcement yet.

Getting The Original SWF Dimensions In UnrealScript

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

    Getting The Original SWF Dimensions In UnrealScript

    This short tutorial provides two methods to explains how to easily get the original dimensions (width and height) of your SWF file in UnrealScript. The dimensions are found in the Document Settings of your FLA file. The tutorial assumes you have a HUD wrapper class which instantiates your HUD.


    Method 1

    First, your HUD Flash file should have the following ActionScript on Frame 1:

    ActionScript 2.0

    Code:
    _global.gfxExtensions = true;
    
    var MovieWidth:Number = Stage["originalRect"].width;
    var MovieHeight:Number = Stage["originalRect"].height;
    Then, in your UnrealScript HUD Wrapper (NOTE: The code related to this tutorial is in red):

    UnrealScript

    Code:
    class SFHudWrapper extends UTHUDBase;
    
    var SFHud          HudMovie;
    var class<SFHud>   HudClass;
    var vector2D       HudMovieSize;
    
    simulated function PostBeginPlay()
    {
        Super.PostBeginPlay();
        CreateHUDMovie();
    	
        HudMovieSize = GetMovieSize(HudMovie);
        `log("Movie Dimensions: " @ int(HudMovieSize.X) @ "x" @ int(HudMovieSize.Y));
    }
    
    function CreateHUDMovie()
    {
        HudMovie = new HudClass;
        HudMovie.SetTimingMode(TM_Real);
        HudMovie.Init(class'Engine'.static.GetEngine().GamePlayers[HudMovie.LocalPlayerOwnerIndex]);	
        HudMovie.SetViewScaleMode(SM_NoScale); // SWF will be drawn at original dimensions regardless of Unreal client resolution
        HudMovie.SetAlignment(Align_TopLeft); // SWF's top left corner at top left corner of Unreal client window.
    }
    
    function vector2D GetMovieSize(GFxMoviePlayer Movie)
    {
        local vector2D MovieSize;
    	
        MovieSize.X = Movie.GetVariableNumber("_root.MovieWidth");
        MovieSize.Y = Movie.GetVariableNumber("_root.MovieHeight");
    	
        return MovieSize;
    }
    
    defaultproperties
    {
        HudClass = class'SFHud'
    }
    Method 2

    No ActionScript required.

    UnrealScript

    Code:
    var GFxObject HudMovieSize;
    
    simulated function PostBeginPlay()
    {
        Super.PostBeginPlay();
        CreateHUDMovie();
    	
        HudMovieSize = HudMovie.GetVariableObject("Stage.originalRect");
    
        `log("Movie Dimensions: " @ int(HudMovieSize.GetFloat("width")) @ "x" @ int(HudMovieSize.GetFloat("height")));
    }

    #2
    Very nice, will this in turn be used to scale the SWF to fit any screen resolution?

    Comment


      #3
      For details on how to do that, see this post:

      http://forums.epicgames.com/showthread.php?t=759121

      Comment


        #4
        Oh i see i might of mixed the two, well what would be the practical uses of getting the dimensions of your SWF movie?

        Thanks for the link :P


        Edit : Thanks for letting me know vv

        Comment


          #5
          You may need to know the size of your SWF for mouse coordinate functions. Such as in the discussion found here: http://forums.epicgames.com/showthread.php?t=751705

          Comment


            #6
            Bump ! Is this code still working today ? I tried to use the code of the method 2 but it does always return me 0x0 in log...

            Comment


              #7
              We currently use:

              Code:
              function IntPoint GetFlashSize()
              {
              	local IntPoint flashSize;
              	if(mFlashWidth == 0)
              	{
              		mFlashWidth =  GetVariableInt("loaderInfo.width");
              	}
              	if(mFlashHeight == 0)
              	{
              		mFlashHeight = GetVariableInt("loaderInfo.height");
              	}
              	flashSize.X = mFlashWidth;
              	flashSize.Y = mFlashHeight;
              	return flashSize;
              }

              Comment


                #8
                Hey ! Thank you for the reply !

                However, can you please tell me what is the type of mFlashWidth and mFlashHeight ? Because I tried to set them as Int and IntPoint but it's always failing (bad token).

                Comment


                  #9
                  Strange, they are just:

                  Code:
                  var protected int mFlashWidth,mFlashHeight;
                  Are you inside of a GFXMoviePlayer? Only it has the "GetVariableInt" function and it returns an int.

                  Comment


                    #10
                    Following some outdated tutorials on the UDN, I was working in MouseInterfaceInput ! Now I switched to my class extending from GFXMoviePlayer and I get "UGFxMoviePlayer::GetVariableInt(): value is not a number"

                    Code:
                    function int GetHUDWidth()
                    {
                    	return GetVariableInt("loaderInfo.width");
                    }
                    
                    function int GetHUDHeight()
                    {
                    	return GetVariableInt("loaderInfo.height");
                    }
                    Do you think there is something inside the SWF that must be edited ? I will actually try the first and longest method of the first post until I got a reply...

                    Comment


                      #11
                      Okay this is the fourth method I tried and it's still not working.

                      I'm going to contact Matt Doyle to inform him that his tutorials are completely broken and outdated.

                      Comment


                        #12
                        "UGFxMoviePlayer::GetVariableInt(): value is not a number"
                        That's strange, the function is returning an int and you expect an int. Where does number come in?

                        No we have nothing special in the Movie. loaderInfo.width and loaderInfo.height are standard variables.

                        Oh I have an idea!

                        Be sure to call:

                        Code:
                        Super.Start();
                        Advance(0);
                        before, these 2 lines initialize the movie and should make the loaderinfo available.

                        Comment


                          #13
                          I already have these two lines of code in my Init function, but it's not working either...

                          more of my code :

                          MyMouseInterfaceOutput (extending from CustomInput)
                          Code:
                          var int HudX, HudY;
                          // This function gets the original width and height of the HUD SWF and stores those values in HudX and HudY.
                          function GetHudSize()
                          {
                          	local playerHUD playerHUD;
                          	playerHUD = playerHUD(myHUD);
                          	HudX = playerHUD.HudMovie.GetHUDWidth();
                              	HudY = playerHUD.HudMovie.GetHUDHeight();
                          	`log("Movie Dimensions: " @ HudX @ "x" @ HudY);
                          }
                          MyGFXHUD (extending from GFXMoviePlayer)
                          Code:
                          function int GetHUDWidth()
                          {
                          	return GetVariableInt("loaderInfo.width");
                          }
                          
                          function int GetHUDHeight()
                          {
                          	return GetVariableInt("loaderInfo.height");
                          }
                          My hud extends from HUD (not UDKHUD or UTHUD but just HUD)
                          Code:
                          simulated function PostBeginPlay()
                          {
                          	super.PostBeginPlay();
                          		
                          	// Create and run the HUD
                          	HudMovie = new class'playerGFxHUD';
                          	HudMovie.SetTimingMode(TM_Real);
                          	HudMovie.InitHUD();
                          	HudMovie.SetViewScaleMode(SM_ExactFit);
                          	HudMovie.SetAlignment(Align_TopLeft);
                          	PlayerMouseInterfaceInput = PlayerMouseInterfaceInput(PlayerOwner.PlayerInput);
                          }
                          part of the log
                          [0009.72] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.72] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.72] ScriptLog: Movie Dimensions: 0 x 0
                          [0009.79] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.79] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.79] ScriptLog: Movie Dimensions: 0 x 0
                          [0009.80] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.80] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.80] ScriptLog: Movie Dimensions: 0 x 0
                          [0009.85] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.85] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.85] ScriptLog: Movie Dimensions: 0 x 0
                          [0009.93] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.93] Log: UGFxMoviePlayer::GetVariableInt(): value is not a number. Returning 0.
                          [0009.93] ScriptLog: Movie Dimensions: 0 x 0
                          Gosh, this problem is really starting to be painful !

                          Comment

                          Working...
                          X