0

Hi (excuse me if there are grammar mistakes, I'm french),

I'm a beginner in AS3 but I know a bit better Flashpunk; whatever, I have really some difficulties to code in AS3 and can't get how to insert a video in an AS3 project using FlashDevelop.

Well I found some code for what I'm looking for, insert a flv video, here : http://www.flashdevelop.org/community/viewtopic.php?f=9&t=6407

But I have some issues to get this code working... As I said before I know better Flashpunk so it's hard for me to link basic AS3 with my knowledges in Flashpunk.

I tried to organize it in classes but I know these are wrong, but please, can anyone tell me how I should do to get the code working ? I think the "addChild" is only a Sprite or Movieclip function so my FLVplayback and PlayerGfx extend Sprite, but I don't know how to add them and display them... Here is my code :

public class testMyWorld extends World
{
    public var player:PlayerGfx;
    public var _FLV:testFLV;

    public function testMyWorld() 
    {

        _FLV = new testFLV;
        player = new PlayerGfx();

    }

}  


public class testFLV extends Sprite
{
    public var flvPlayback:FLVPlayback;
    public var player:PlayerGfx;

    public function testFLV() 
    {
        flvPlayback = new FLVPlayback(); 
        flvPlayback.skin = "none" 
        flvPlayback.autoPlay = false;
        flvPlayback.source = "FLVSkyrim.flv"    
        player.addChild(flvPlayback);
    }

}

and well I didn't know what to put in it but in the link before there is a "player class" so...

    public class PlayerGfx extends Sprite
{

    public function PlayerGfx() 
    {

    }

}

I'm desperately looking for help, I can't find anyone that can explain me what I should do :/ I just need to display a video in as AS3 project for school and I don't want to use FlashProfessional... But I don't understand many things, such as addChild, display a Sprite Class, etc... But if you know an other code better that I could use and that you could explain to me, I would be very grateful.

Thanks in advance !

EDIT : gosh I'm sorry idk if I saw your answers at the time I asked this. The thing is, one of my coworkers at school wrote me a pretty nice bit of code that answered exactly what I needed to do because it was a bit tricky. I can give it to anyone who may need it, but I'm not sure it would suit any "usual" situation because it was pretty personalized and explained irl. Anyway, thanks for your answers.

Lap
  • 11
  • 4

2 Answers2

0

Why is your base class a World? In a pure AS3 project it should be a Sprite. Then, once your player (FLVPlayback) is created, you just have to add it to the display list:

import fl.video.FLVPlayback;

public class Main extends Sprite
{
    private var flvPlayback:FLVPlayback;

    public function testMyWorld() 
    {    
        flvPlayback = new FLVPlayback(); 
        flvPlayback.skin = "none" 
        flvPlayback.autoPlay = false;
        flvPlayback.source = "FLVSkyrim.flv"    
        addChild(flvPlayback);    
    }

}

Be simple, you don't need all those classes ;)

Kodiak
  • 5,978
  • 17
  • 35
0

This is tricky, because FlashPunk replaces the display list by a custom Bitmap-based renderer.

Your World object is not a regular display object and it can't hold a FLVPlayback component.

Your best option is to attach the video player to the stage. Your Main class (extending Engine) is a display object so it has a reference to the stage.

First you need a global reference to your Main instance so you can find the stage:

public class Main extends Engine
{
    static public instance:Main; // global static reference

    public function Main():void
    {
         instance = this;
         ...
    }
}

Now you can attach display objects on the stage (over the FlashPunk stage):

public class testMyWorld extends World
{
    private var player:MyPlayer; // your FLV player class extending Sprite

    public function testMyWorld() 
    {
        player = new MyPlayer();
    }

    // when the world is shown
    override public function begin():void 
    {
         Main.instance.stage.addChild(player);
    }

    // when the world is hidden
    override public function end():void 
    {
         if (player.parent) Main.instance.stage.removeChild(player);
    }
}

PS: I didn't actually run this code

Philippe
  • 2,621
  • 1
  • 19
  • 20