Posts Tagged ‘Actionscript3’

This tutorial will assume that you have already created your custom video buttons, and allocated them the name of

  • pauseBtn
  • playBtn
  • stopBtn

now to allow the buttons to actualy do something with the current FLV video, we need to link the buttons to some actionscript code in order to do this you must first open up the actions frame dialogue (press F9) and write the following basic lines of code for basic functionality:

//first we must create the Event Handlers
pauseBtn.addEventListener(MouseEvent.CLICK, pauseHandler);
playBtn.addEventListener(MouseEvent.CLICK, playHandler);
stopBtn.addEventListener(MouseEvent.CLICK, stopHandler);

//Changing cursor to hand, so that the user knows that the button can be pushed
pauseBtn.buttonMode = true;
pauseBtn.useHandCursor = true;
playBtn.buttonMode = true;
playBtn.useHandCursor = true;
stopBtn.buttonMode = true;
stopBtn.useHandCursor = true;
//End Changing cursor to hand

//finaly calling the fucntions for each handler event
function pauseHandler(e:MouseEvent):void{
	vid.pause();
}

function playHandler(e:MouseEvent):void{
	vid.play();
}

function stopHandler(e:MouseEvent):void{
	vid.pause(); //pauses video
	vid.seek(0); //resets it to frame 1
}

and that its, very simple and easy – if you need help in understanding how to add custom buttons and converting them to movieclips, then please leave a comment!

This is a tutorial showing how to create a very clean and basic preloader for Flash CS3, using Actionscript 3.

to begin with  we must create our file.

  1. click on File > New or (Ctrl + N)
  2. Select Flash Actionscript3 and click ok
  3. No we must give it a name, so Click File > Save As and give it a name, i called mine preloader
  4. Once this is done we have the ablity to start editing our file

As usual you can set the file size for the document etc from the properties tab, but you can leave the settings as default if you like.

We now must create a new layer and call it actions, now in frame 1 of the actions tab (if you can not see the Actions tab, press F9) and type the following code:

Read the rest of this entry »

This Part of the Shaders Tutorial series will show you how to add an Environmental Material Shader to your objects.

What this basically does is take a texture imported from the background and use it to reflect off the object, giving the object a highly reflective coating which is faked. This keeps processing power down, while giving a nice effect.

For this tutorial we will be creating an effect that looks something like this: (please be patient while the video loads)

 

If you are a novice, it is advised that you follow this tutorial from the initial section that can be found here, which explains how to set up the files and the scene. Otherwise please read on.

To begin with, we must begin our new package and import our classes.

package environmentMat{
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFormat;

	import org.papervision3d.cameras.CameraType;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.shadematerials.EnvMapMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.view.BasicView;
	//
	import org.papervision3d.objects.parsers.DAE;
	import org.papervision3d.objects.DisplayObject3D;
	//Ability to add materials
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.materials.utils.MaterialsList;

Then initialise our class and create the variables that will be using

public class environmentMat extends Sprite {
		private var view:BasicView;
		private var img:Loader;
		private var environment:EnvMapMaterial;
		private var light:PointLight3D;
		private var sphere:Sphere;
		private var angle:Number = new Number(0);

		private var tf:TextField;
		private var format:TextFormat;

		private var dae:DAE;
		private var daeFile:String;
		private var daeMaterialName:String;

Read the rest of this entry »

Update: As seen in one of the comments, it seems TEXT_INPUT is not the way to go, as it is “Dispatched after a control value is modified, unlike the textInput event, which is dispatched before the value is modified” check out the API

Acording to the Adobe API In Flash, by default a text field’s property is usualy set to “dynamic”, however if you change this property to “input” using the TextFieldType class, then it is possible to save user input for use in other parts of your appication – This is mainly useful when creating forms, or any application that need the user to define a text value somewhere else in the system.

In this tutorials example, the following code creates an imput text field called myFirstTextBox. As the user enters the text, An event is triggered, we will call this inputEvent.
To capture the string of text entered, we need an event handler – we shall call this inputCapture, it will capture the string and assign it a variable – then Flash Player or AIR displays the new text in another text field, called OutputBox.

package
{
  import flash.display.Sprite;
  import flash.display.Stage;
  import flash.text.*;
  import flash.events.*;

  public class CaptureInput extends Sprite
  {
    private var myFirstTextBox:TextField = new TextField();
    private var OutputBox:TextField = new TextField();
    private var myText:String = "Type your text here.";

    public function CaptureUserInput()
    {
      captureText();
    }

    public function captureText():void
    {
      myFirstTextBox.type = TextFieldType.INPUT;
      myFirstTextBox.background = true;
      addChild(myFirstTextBox);
      myFirstTextBox.text = myText;
      myFirstTextBox.addEventListener(TextEvent.TEXT_INPUT, inputEventCapture);
    }

    public function inputEventCapture(event:TextEvent):void
    {
      var str:String = myFirstTextBox.text;
      createOutputBox(str);
    }

    public function createOutputBox(str:String):void
    {
      OutputBox.background = true;
      OutputBox.x = 200;
      addChild(OutputBox);
      OutputBox.text = str;
    }
  }
}

This tutorial will explain how to enable keyboard commands in Flash Actionscript 3 CS3.

Firstly we need to import the Keyboard class in flash this can be done by:

import flash.events.KeyboardEvent;

After we have imported the keyboardEvent package, it is necessary to add an event listener to the stage, otherwise Flash will not know that we are pressing a key, and will not know what to do with it.

stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);

We need to create a function for our KeyPressed event listener but inside our function we create a switch statement to determine what the function should do when a certain key is pressed. Inside our parameters we have the argument evt.KeyCode this gets the key code for the key that was pressed to trigger the event.

function KeyPressed(evt:KeyboardEvent):void {switch (evt.keyCode){
case Keyboard.UP :break;case Keyboard.DOWN :break;case 
Keyboard.LEFT :break;case Keyboard.RIGHT :break;
}
}

After you have specified what keys you would like to use, you can link them for example to move something. For example, if you want a square to move in the x direction when the “up” arrow is pressed on the keyboard you would add square.y += 5;

so the code above would be modified to look like this:

case Keyboard.UP :square.y += 5;break;
Subscribe
Follow me on Twitter
free counters
PayPal Donation
If you like this blog and the help it has given you, why not donate for this good cause? Click on the button below to pay Safely and Securely through PayPal.
Thanks.