Author Topic: Trying to embed a SWF video??  (Read 2213 times)

zxz1661

  • Member
  • **
  • Posts: 62
  • Karma: +0/-0
  • Full of Fail
    • View Profile
Trying to embed a SWF video??
« on: Wed, Jun 1, 2011 »
i am trying to embed the SWF "cutscene.swf" and used a snippet found here.

Here is the code for "Cutscene1.as"

Code: [Select]
package
{
import org.flixel.FlxG;
import org.flixel.FlxState;
import flash.display.MovieClip;
import flash.media.SoundMixer;
import flash.events.Event;
public class Cutscene1 extends FlxState
{
//Embed the cutscene swf relative to the root of the Flixel project here
[Embed(source='org/flixel/data/cutscene.swf')] private var SwfClass:Class;
//This is the MovieClip container for your cutscene
private var movie:MovieClip;
//This is the length of the cutscene in frames
private var length1:Number;
 
override public function create():void
{
movie = new SwfClass();
//Set your zoom factor of the FlxGame here (default is 2)
var zoomFactor:int = 2;
movie.scaleX = 1.0/zoomFactor;
movie.scaleY = 1.0 / zoomFactor;
//Add the MovieClip container to the FlxState
addChildAt(movie, 0);
//Set the length of the cutscene here (frames)
length1 = 100;
//Adds a listener to the cutscene to call next() after each frame.
movie.addEventListener(Event.EXIT_FRAME, next);
}
private function next(e:Event):void
{
//After each frame, length decreases by one
length1--;
//Length is 0 at the end of the movie
if (length1 <= 0)
{
//Removes the listener
movie.removeEventListener(Event.EXIT_FRAME, next);
//Stops all overlaying sounds before state switch
SoundMixer.stopAll();
//Enter the next FlxState to switch to
FlxG.switchState(new MenuGame)
}
}
}
}

and the error i'm getting is:

col: 4 Error: Call to a possibly undefined method addChildAt.
addChildAt(movie, 0);

zadvornykh

  • Active Member
  • ***
  • Posts: 205
  • Karma: +1/-0
    • View Profile
Re: Trying to embed a SWF video??
« Reply #1 on: Wed, Jun 1, 2011 »
You are extending FlxState in your class, which is itself does not extend a display object (like sprite or movieclip), so it has no add child method.

You can access the stage through FlxG.state and add your movie directy to that. You will also need to add it at the top index, instead of 0, or it will be behind your game. Just use addChild in stead of addChildAt.

zxz1661

  • Member
  • **
  • Posts: 62
  • Karma: +0/-0
  • Full of Fail
    • View Profile
Re: Trying to embed a SWF video??
« Reply #2 on: Wed, Jun 1, 2011 »
OK. I changed the 0 and addchildat to AddChild, but do i need too extend FlxG? What do i have to change in the scripts (sorry, mega-noob)

zadvornykh

  • Active Member
  • ***
  • Posts: 205
  • Karma: +1/-0
    • View Profile
Re: Trying to embed a SWF video??
« Reply #3 on: Wed, Jun 1, 2011 »
replace the line where you addChildAt with:

Code: [Select]
FlxG.stage.addChild(movie);

zxz1661

  • Member
  • **
  • Posts: 62
  • Karma: +0/-0
  • Full of Fail
    • View Profile
Re: Trying to embed a SWF video??
« Reply #4 on: Thu, Jun 2, 2011 »
How can i make it hide after it's done playing?
I tried destroy() and MovieClip.exists = false but i don't know what to do.

zadvornykh

  • Active Member
  • ***
  • Posts: 205
  • Karma: +1/-0
    • View Profile
Re: Trying to embed a SWF video??
« Reply #5 on: Fri, Jun 3, 2011 »
You can check the current frame of the movieclip against the total frames of the movieclip, and remove it from the display list when it is done playing.

Add this code to your update function:

Code: [Select]
if(movie.currentFrame == movie.totalFrames)
{
 FlxG.stage.removeChild(movie);
}

paala

  • Contributor
  • ****
  • Posts: 250
  • Karma: +0/-1
    • View Profile
Re: Trying to embed a SWF video??
« Reply #6 on: Fri, Aug 26, 2011 »
This is my class working 100% in Flixel 2.55
Code: [Select]
package com.bla.game
{
import org.flixel.FlxG;
import org.flixel.FlxState;
import flash.display.MovieClip;
import flash.media.SoundMixer;
import flash.events.Event;
import org.flixel.*;
//import flash.display.Sprite;

public class LogoCutscene extends FlxState
{
//Embed the cutscene swf relative to the root of the Flixel project here
[Embed(source = '../../../../art/logo8.swf')] private var Swflass:Class;
//This is the MovieClip container for your cutscene
private var movie:MovieClip;
//This is the length of the cutscene in frames
private var lengthh:Number;
 
override public function create():void
{
movie = new Swflass();//inainte era swf Class acuma e swf class
//Set your zoom factor of the FlxGame here (default is 2)
var zoomFactor:int = 2;
movie.scaleX = 1.0/zoomFactor;
movie.scaleY = 1.0 / zoomFactor;
//Add the MovieClip container to the FlxState
FlxG.stage.addChild(movie);

//Set the length of the cutscene here (frames)
lengthh = 100;
//Adds a listener to the cutscene to call next() after each frame.
movie.addEventListener(Event.EXIT_FRAME, next);
}
/*override public function update():void
{
if(movie.currentFrame == movie.totalFrames)
{
 FlxG.stage.removeChild(movie);
}
}*/
private function next(e:Event):void
{
//After each frame, length decreases by one
lengthh--;
//Length is 0 at the end of the movie
if (lengthh <= 0)
{
//Removes the listener
movie.removeEventListener(Event.EXIT_FRAME, next);
FlxG.stage.removeChild(movie);
//Stops all overlaying sounds before state switch
SoundMixer.stopAll();
//Enter the next FlxState to switch to
FlxG.switchState( new MenuMain);
}
}
}
}

Changes from code http://flashgamedojo.com/wiki/index.php?title=Cutscene_Template:
1. FlxG.switchState( new MenuMain);
2. length-> lengthh
3. SwfClass->  Swflass
4 FlxG.stage.removeChild(movie);
5. FlxG.stage.removeChild(movie);