Announcement

Collapse
No announcement yet.

Making swf animation play in game

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

    #16
    hey looks like your nearly there , if you want to use the GotoAndPlay(); function you create a new layer in flash and make a keyframe where ever you want the movie to play/stop at and put a name in label Name box in properties:




    Reimport the flash .swf into UDK, then you can use RootMC.GotoAndPlay("SoundMenu");

    Its strange that RootMC.gotoAndPlayI(2); doesn't work though, have you tried `log("RootMC is: "@RootMC); to make sure GetVariableObject("_root"); is not none, should be getting the root of the swf file?

    Comment


      #17
      I labeled the second frame and changed the command to fit it, though it didn't play.

      I also put the log command in the same bracket as the gotoAndPlay() and nothing came up in the Log window. None of my logs seem to be at all, but I'm fairly sure that it isn't getting the root variable though, as if the Stop() command is working I don't see why the others aren't, hm... It's probably some very simple mistake I've made somewhere...

      Currently have:

      Code:
      class ChilledHUD_Book extends GFxMoviePlayer;
      
      var GFxClikWidget NextButton1;
      var GFxObject RootMC;
      
      
      function Init(optional LocalPlayer LocPlay)
      {
      	LocalPlayerOwnerIndex = class'Engine'.static.GetEngine().GamePlayers.Find(LocPlay);
      	if(LocalPlayerOwnerIndex == INDEX_NONE)
      	{
      		LocalPlayerOwnerIndex = 0;
      	}
      
      	if(MovieInfo != None)
      	{
      		Start();
      		Advance(0.f);
      		ConfigAll();
      	}
      }
      
      
      function ConfigAll()
      {
      	RootMC = GetVariableObject("_root");
      
      	if(RootMC != none)
      	{
      		NextButton1 = GFxClikWidget(RootMC.GetObject("nextButton1", class'GFxClikWidget'));
      		
      	}
      	if(NextButton1 != none)
      	{
      		NextButton1.AddEventListener('CLIK_click', TurnPage);
      	}
      }
      
      
      function bool Start(optional bool StartPaused = false)
      {
      	Super.Start();
      
      	Advance(0);
      
      	return true;
      }
      
      
      function TurnPage(EventData data)
      {
      	if(data.mouseIndex == 0)
      	{
      		RootMC.gotoAndPlayI(2);
      		//Also used RootMC.gotoAndPlay("FirstFlip");
      		`log("RootMC is: "@RootMC);
      	}
      }
      
      
      defaultproperties
      {
      	MovieInfo=SwfMovie'ChilledHUD.UI_Book'
      
      	WidgetBindings.Add((WidgetName="nextButton1",WidgetClass=class'GFxCLIKWidget'))
      	
      	bDisplayWithHudOff=TRUE
      	TimingMode=TM_Real
      		bPauseGameWhileActive=TRUE
      		bCaptureInput=true
      }
      And my recent log:

      Comment


        #18
        Now that you have enabled InitCallback on your button you should be able to use WidgetInitialized event again, try the code below and check your log to see if RootMC is there.

        Code:
        class ChilledHUD_Book extends GFxMoviePlayer;
        
        /** Reference to _root of the movie's stage. */
        var GFxObject RootMC;
        /** Reference to the nextButton1 MovieClip (_root.nextButton1) */
        var GFxClikWidget NextButton1;
        
        var bool bInitialized;
        
        function bool Start(optional bool StartPaused = false)
        {
        	Super.Start();
        	Advance(0);
        
        	if (!bInitialized)
        	{
        		ConfigAll();
        	}
        
        	return true;
        }
        
        /** 
         *  Configuration method which stores references to _root.
         */
        final function ConfigAll()
        { 
        	RootMC = GetVariableObject("_root");
        
        	`log("RootMC is:"@RootMC);
        
        	bInitialized = TRUE;
        }
        
        /** 
         *  Callback when a CLIK widget with enableInitCallback set to TRUE is initialized.  
         *  Returns TRUE if the widget was handled, FALSE if not. 
         */
        event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
        {
        	local bool bWasHandled;
        	bWasHandled = FALSE;
        
        	switch(WidgetName)
        	{
        		case 'nextButton1':
        			NextButton1 = GFxCLIKWidget(Widget);
        			`log("NextButton1 is:"@NextButton1);
        			NextButton1.AddEventListener('CLIK_click', TurnPage);
        			bWasHandled = TRUE;
        			break;
        		default:
        			break;
        	}
        
        	if (!bWasHandled)
        	{
        		bWasHandled = Super.WidgetInitialized(WidgetName, WidgetPath, Widget); 
        	}
        	return bWasHandled;
        }
        
        function TurnPage(GFxClikWidget.EventData data)
        {
        	`log("- TurnPage Called! -");
        	`log("data.mouseIndex is:"@data.mouseIndex);
        	if(data.mouseIndex == 0)
        	{
        		RootMC.GotoAndPlay("FirstFlip");
        	}
        }
        
        
        defaultproperties
        {
        	bAllowInput=TRUE
        	bAllowFocus=TRUE
        	bDisplayWithHudOff=TRUE
        	TimingMode=TM_Real
        	bPauseGameWhileActive=TRUE
        	bCaptureInput=TRUE
        	bCaptureMouseInput=TRUE
        
        	MovieInfo=SwfMovie'ChilledHUD.UI_Book'
        
        	WidgetBindings.Add((WidgetName="nextButton1",WidgetClass=class'GFxCLIKWidget'))	
        }
        This is kind of how GFxUDKFrontEnd is set up, if this still doesn't work can you post a screenshot of your flash timeline and library?.

        Edit:

        Thinking it over RootMC must be valid otherwise the code below wouldn't work and your button would have never worked either, I'm guessing it's maybe the data.mouseIndex so I added bCaptureMouseInput, I remember reading somewhere that some were having problems with mouseIndex, it maybe better to remove that control statement from the function:

        Code:
        function ConfigAll()
        {
        	RootMC = GetVariableObject("_root");
        
        	if(RootMC != none)
        	{
        		NextButton1 = GFxClikWidget(RootMC.GetObject("nextButton1", class'GFxClikWidget'));
        		
        	}
        	if(NextButton1 != none)
        	{
        		NextButton1.AddEventListener('CLIK_click', TurnPage);
        	}
        }

        Comment


          #19
          It completely WORKS! Now I just need to duplicate it for the next page and pretty it up visually, but that will be a piece of cake compared to all this. I can't thank you enough!

          Here is the final assembly of code you gave me, just in one piece. I had been retyping it into my own but I decided to just copy it over this time to avoid any mistakes for now. I'm sure if anyone else has this problem it will be well documented for them, heh!

          Code:
          class ChilledHUD_Book extends GFxMoviePlayer;
          
          /** Reference to _root of the movie's stage. */
          var GFxObject RootMC;
          /** Reference to the nextButton1 MovieClip (_root.nextButton1) */
          var GFxClikWidget NextButton1;
          
          var bool bInitialized;
          
          function bool Start(optional bool StartPaused = false)
          {
          	Super.Start();
          	Advance(0);
          
          	if (!bInitialized)
          	{
          		ConfigAll();
          	}
          
          	return true;
          }
          
          /** 
           *  Configuration method which stores references to _root.
           */
          final function ConfigAll()
          {
          	RootMC = GetVariableObject("_root");
          
          	if(RootMC != none)
          	{
          		NextButton1 = GFxClikWidget(RootMC.GetObject("nextButton1", class'GFxClikWidget'));
          		
          	}
          	if(NextButton1 != none)
          	{
          		NextButton1.AddEventListener('CLIK_click', TurnPage);
          	}
          }
          
          /** 
           *  Callback when a CLIK widget with enableInitCallback set to TRUE is initialized.  
           *  Returns TRUE if the widget was handled, FALSE if not. 
           */
          event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
          {
          	local bool bWasHandled;
          	bWasHandled = FALSE;
          
          	switch(WidgetName)
          	{
          		case 'nextButton1':
          			NextButton1 = GFxCLIKWidget(Widget);
          			`log("NextButton1 is:"@NextButton1);
          			NextButton1.AddEventListener('CLIK_click', TurnPage);
          			bWasHandled = TRUE;
          			break;
          		default:
          			break;
          	}
          
          	if (!bWasHandled)
          	{
          		bWasHandled = Super.WidgetInitialized(WidgetName, WidgetPath, Widget); 
          	}
          	return bWasHandled;
          }
          
          function TurnPage(EventData data)
          {
          	`log("- TurnPage Called! -");
          	`log("data.mouseIndex is:"@data.mouseIndex);
          	if(data.mouseIndex == 0)
          	{
          		RootMC.GotoAndPlay("FirstFlip");
          	}
          }
          
          
          defaultproperties
          {
          	bAllowInput=TRUE
          	bAllowFocus=TRUE
          	bDisplayWithHudOff=TRUE
          	TimingMode=TM_Real
          	bPauseGameWhileActive=TRUE
          	bCaptureInput=TRUE
          	bCaptureMouseInput=TRUE
          
          	MovieInfo=SwfMovie'ChilledHUD.UI_Book'
          
          	WidgetBindings.Add((WidgetName="nextButton1",WidgetClass=class'GFxCLIKWidget'))	
          }

          Comment


            #20
            Awesome! Glad you got it working, in the words of Samuel Smiles
            "We learn wisdom from failure much more than from success."


            Although looking through your final code you could remove the code below from the ConfigAll function:
            Code:
            	if(RootMC != none)
            	{
            		NextButton1 = GFxClikWidget(RootMC.GetObject("nextButton1", class'GFxClikWidget'));
            		
            	}
            	if(NextButton1 != none)
            	{
            		NextButton1.AddEventListener('CLIK_click', TurnPage);
            	}
            WidgetInitialized should take care of initializing any buttons, that piece of code above is an alternative to using WidgetInitialized the major drawback with the code above is the button would have to be on the first frame of your timeline for it to work and that's not always acceptable, using WidgetInitialized you can place your buttons wherever you want on the timeline and the button(with enableInitCallback set to true) will fire off the WidgetInitialized event, this makes it the preferred method to use.

            You can leave the code as it stands but essentially the job of getting reference to the button is being done twice which isn't efficient.

            good luck with the rest of it.

            Comment


              #21
              Yes, good point. I'll optimize that quickly.

              Well, I have the full swf functioning in UDK now! Thanks again!

              Comment

              Working...
              X