0
votes

I want to create a simple balloon shooter with Actionscript. The balloons should float from the bottom to the top end of the stage. There will be two kinds of balloons. One will carry a frame, where the image of the webcam is attached. If you shoot the one without the image, you get 100 points. If you shoot the one with the image, you lose.

My solution so far addresses every single element (graphics as well as the video) individually. This would mean, that I have to write that code for a couple of times for every ballon that should rise. This seems not very efficient. Also, the amount of balloons is limited.

import flash.media.Camera;
import flash.media.Video;
import flash.display.MovieClip;

var camera:Camera = Camera.getCamera();

if (camera != null)
{

    videoFrame1.attachCamera(camera);
}
else
{
    trace("You need a camera.");


}

stop();

Score.appendText("Your Score: ");


//Balloon1 

var directionY1;

video1.addEventListener(Event.ENTER_FRAME, float1);
function float1(event:Event)
{
    if (video1.y > 0)
    {
        richtungY1 = 1;
    }
    video1.y -=  3 * directionY1;
}

videoFrame1.addEventListener(Event.ENTER_FRAME, Framefloat1);
function Framefloat1(event:Event)
{
    if (videoFrame1.y > 0)
    {
        directionY1 = 1;
    }
    videoFrame1.y -=  3 * directionY1;
}

clickFrame1.addEventListener(Event.ENTER_FRAME, clickFramefloat1);
function clickFramefloat1(event:Event)
{
    if (clickFrame1.y > 0)
    {
        directionY1 = 1;
    }
    clickFrame1.y -=  3 * directionY1;
}
balloon1.addEventListener(Event.ENTER_FRAME, Balloonfloat1);
function Balloonfloat1(event:Event)
{
    if (balloon1.y > 0)
    {
        directionY1 = 1;
    }
    balloon1.y -=  3 * directionY1;
}

tv1.addEventListener(Event.ENTER_FRAME, TVfloat1);
function TVfloat1(event:Event)
{
    if (tv1.y > 0)
    {
        directionY1 = 1;
    }
    tv1.y -=  3 * directionY1;
}


function clicked(event:MouseEvent):void
{
    removeChild(videoFrame1);
    removeChild(tv1);
    removeChild(balloon1);
}
clickFrame1.addEventListener(MouseEvent.CLICK, clicked);

//Counter;

clickFrame1.addEventListener(MouseEvent.CLICK, count);
var counter = 0;
function count( e:MouseEvent ):void
{

    counter +=  100;
    Score.appendText(counter);
    trace( counter );

}

Now, my idea was to build one kind of each balloon, and load it out of the library. I thought about using addChild. If you shoot one balloon, a new one should be generated, with increased speed. But I couldn't work it out.

It seems I can't put the video inside a movieClip and combine it with the other elements to one object.

Does anyone have an idea, how I could create a movieClip, with all the elements inside, and load it out of the library?

Thank you very much in advance!

1

1 Answers

0
votes

This tutorial explains how to load assets from the library to the timeline: http://www.adobe.com/devnet/flash/quickstart/loading_images_library_as3.html. It will get you started.