Announcement

Collapse
No announcement yet.

Making swf animation play in game

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

    Making swf animation play in game

    Hello! I've been spending several hours looking high and low for this answer, but either it's just out of reach or I'm not using the right keywords, so I'm going to ask to see if anyone here can help!

    What I'm trying to do is make a book popup on screen. It is stopped on the first frame, and on clicking a button, the swf will play the page turning and stop at frame 20. It will do the same from another button, ending at 40. I have it opening and stopping in game, but clicking the button isn't causing the animation to play. I have good idea what the problem is, but the solution is just outside my knowledge.

    Following some written guides, I've so far come up with this for the book's uc file:

    Code:
    class ChilledHUD_Book extends GFxMoviePlayer;
    
    var GFxCLIKWidget NextButton1;
    
    function bool Start(optional bool StartPaused = false)
    {
    	Super.Start();
    	Advance(0);
    	return true;
    }
    
    
    event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
    {
    	switch(WidgetName)
    	{
    		case 'nextButton1':
    			NextButton1 = GFxCLIKWidget(Widget);
    			NextButton1.AddEventListener('CLIK_click', TurnPage);
    			break;
    		default:
    			return Super.WidgetInitialized(Widgetname, WidgetPath, Widget);
    	}
    	return false;
    }
    
    
    function TurnPage(EventData data)
    {
    	if(data.mouseIndex == 0)
    	{
    		Play();
    	}
    }
    
    
    defaultproperties
    {
    	MovieInfo=SwfMovie'ChilledHUD.UI_Book'
    	WidgetBindings.Add((WidgetName="nextButton1",WidgetClass=class'GFxCLIKWidget'))
    	bDisplayWithHudOff=TRUE
    	TimingMode=TM_Real
    		bPauseGameWhileActive=TRUE
    		bCaptureInput=true
    }
    That "Play();" line is where I know some if not all the trouble is in, considering it gives me an error while compiling, it's mostly just there to show intent at this point. I've tried several other options for that line, including trying to make an "on(release){gotoAndPlay(2);}" on the button in flash, but they have not given results. It's likely something really simple, but I'm not very experienced with Unreal Scripting and can't seem to find the right answer online. I've shown the whole code just in case there are more issues I'm not aware of.

    Thanks!

    #2
    you need to access the _root timeline of the movieclip(or stage in flash) to control playing/stopping.

    Very often programmers use the Init function to erm... initialise and cache all the variables needed .

    Code:
    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");
    }
    Then you would use RootMC .gotoAndPlay(2); to move the main timeline.

    If your book page turning animation is inside a MovieClip and not the root of the .swf then you would need to get a reference to it.

    Code:
    var GFxObject Book_MC;
    
    Book_MC = GetVariableObject("_root.Book_MC");
    Then obviously you would use Book_MC .gotoAndPlay(2); to control its timeline.

    Edit:
    forgot to add that "Book_MC" would be the instance name of the movieclip within your flash document, if your movieclips instance name is left blank the GetVariableObject function will not be able to find it and it will return none, just to avoid confusion.

    Comment


      #3
      Thanks! I've worked that in (just the first part, since the animation is all on the stage) and the code seems to like that part. Though now it's giving me a compiling error for "Type mismatch in Call to 'gotoAndPlay', parameter 1" over the edited line "RootMC.gotoAndPlay(2);".

      Comment


        #4
        Apologies if you use function GotoAndPlay() it requires a string, you would normally use frame labels, if you use function GotoAndPlayI(2) that takes an integer value, and that should work.

        Comment


          #5
          Yeah, that makes it accept the code! Though the fact that it doesn't play when I click it makes me think I must have set something up wrong in the flash file, perhaps. The button has the correct instance name 'nextButton1' and was exported for ActionScript if that matters, and it seems to register being clicked in UDK, it just isn't carrying anything out. Is there anything I may have missed?

          Comment


            #6
            Have you enabled InitCallback on your button?



            that's an easy one to miss, also flash is case sensitive so watch that one.. erm can't think of anything else at the minute..

            are you using AS3 or AS2?

            Edit:

            You could always try logging to see WidgetInitialized is called, or log RootMC to see if its none?

            also your WidgetInitialized function should look more like this, when a widget is initialised the return value should be true.

            Code:
            event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
            {
            	local bool bWasHandled;
            	bWasHandled = false;
            
            	switch(WidgetName)
            	{
            		case 'nextButton1':
            			NextButton1 = GFxCLIKWidget(Widget);
            			NextButton1.AddEventListener('CLIK_click', TurnPage);
            			bWasHandled = true;
            			break;
            		default:
            			break;
            	}
            
            	if (!bWasHandled)
            	{
            		bWasHandled = Super.WidgetInitialized(WidgetName, WidgetPath, Widget); 
            	}
            	return bWasHandled;
            }

            Comment


              #7
              AS2, though I'm using it on Flash CS5. After being unable to locate that tab and wondering where it was, a search has told me from one person that the Component Parameters tab there doesn't seem to show up in CS5, for some reason.

              Edit:

              I fixed up the WidgetInitialized function, and changed the TurnPage function to add in some logs to see if this function is even called properly, and neither appeared in the log window.

              Code:
              function TurnPage(EventData data)
              {
              	`log("TurnPage called");
              	if(data.mouseIndex == 0)
              	{
              		RootMC.gotoAndPlayI(2);
              		`log("Clicked successfully");
              	}
              }

              Comment


                #8
                Okay I'm not overly familiar with AS2, I use AS3 predominantly and don't know what events are or more importantly not in AS2 but try modifying the ConfigAll function to this and adding the var GFxClikWidget NextButton1 to the top of the class:

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

                Comment


                  #9
                  Hm, it didn't change anything, I get a feeling that it is due to the lack of enabling InitCallback as that is the only condition so far which I can't carry out.

                  Comment


                    #10
                    Well I'm stumped, this is a silly question but you are using clik components? is nextButton1 on the first frame? ... I looked in Development\Flash\AS2\CLIK\components folder opened Button.fla and none of the buttons have enableInitCallback in the component parameters, but udk_pausemenu.fla in UDKGame\Flash\UDKHud uses AS2 and has buttons with enableInitCallback available



                    although it's strange how you cannot see the component parameters for the button, but i'm all out of ideas, maybe someone with AS2 experience can chip in?

                    Comment


                      #11
                      I'm fine with any silly or obvious questions at this point, since yeah this is just really confusing. I'm tempted to learn how to do the whole thing in AS3 at this point, but I'm still not sure if being unable to use that tab would prevent me from using that either.



                      I notice yours says it's a Movie Clip and not a button, however! Though the other movie clips on the stage don't have the tab available, either.

                      Comment


                        #12
                        yeah standard movieclips doesn't have the components tab, just flash components have the components tab, where did you get your button from? was is the components library below?



                        or did you open Development\Flash\AS2\CLIK\components folder Button.fla and copy paste the button from there into your document?

                        Edit
                        I'm using flash CS5.5 by the way and the component parameters tab is visible.

                        Comment


                          #13
                          I made the button manually, and that is likely the source of the problem... Which of the two would you recommend getting it from?

                          Comment


                            #14
                            The way Matt Doyle from Scaleform has recommended is opening Development\Flash\AS2\CLIK\components\Button.fla and copy pasting the button from there into your document, give it an instance name. Although if you can't access the buttons component parameters from CS5 I think you will be stuck.

                            However this button will still not have the enableInitCallback checkbox, but if its on the first frame of your timeline then the code snippet below should work:

                            Code:
                            class ChilledHUD_Book extends GFxMoviePlayer;
                            
                            var GFxObject RootMC;
                            var GFxCLIKWidget NextButton1;
                            
                            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);
                            	}
                            }
                            
                            
                            defaultproperties
                            {
                            	MovieInfo=SwfMovie'ChilledHUD.UI_Book'
                            	bDisplayWithHudOff=TRUE
                            	TimingMode=TM_Real
                            	bPauseGameWhileActive=TRUE
                            	bCaptureInput=true
                            }
                            Alternatively if you open up UDKGame\Flash\UDKHud\udk_pausemenu.fla there are examples of how UDK uses scaleform buttons, most button component from the library have extra parts you wont need and there maybe a better button example from another file available, but essentially the enableInitCallback checkbox should be available in the component.

                            But as before if you can't access the button component parameters from CS5 you will be stuck.

                            if you manage to find and then use a button component with an enableInitCallback checkbox, the original code before modifying the ConfigAll() should work and WidgetInitialized should be called... confused? I am

                            Comment


                              #15
                              Having had to take a break, I managed to find the button from there and enabled InitCallback (had to open the components inspector tab briefly to make it appear), gave it the correct instance name... and found out that I had not checked on 'capture input' in the Open GFx module in Kismet. I had earlier replaced the GotoAndPlay line with Close(); just as a test, and clicking it closes it! It works, and I just could not believe it!

                              Though once I reactivated "RootMC.gotoAndPlayI(2);" and turned that off, it does not. I will try to mess around with that line, maybe even find a way to just make a gotoAndPlay() on its own like you said earlier, and will report back successes or failures, but if there are any suggestions I'm completely open.

                              Thank you so much!

                              Comment

                              Working...
                              X