Error in File Class? - actionscript-3

I have a button at the stage of the name "butdin" And add him as the class : I want to when you press the Menu button in the file show Why button does not work..
package {
import flash.display.MovieClip;
import flash.system.fscommand;
import flash.media.SoundMixer;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import fl.display.ProLoader;
import flash.system.fscommand;
import fl.video.FLVPlayback;
import flash.display.StageAlign;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.controls.List;
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
import flash.display.SimpleButton;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.MovieClip;
import fl.controls.Button;
import flash.display.SimpleButton;
public class butdin extends SimpleButton {
butdin.addEventListener(MouseEvent.CLICK, sayit);
public function sayit(e : MouseEvent) : void {
var list : List = new List();
list.setSize(361, 291);
list.move(421, 254);
var i : uint;
for (i = 1; i < 8; i++) {
list.addItem({label:"Track " + i});
}
list.addItem({label:"Track 1"});
list.addItem({label:"Track 2"});
list.addItem({label:"Track 3"});
list.addItem({label:"Track 4"});
list.addItem({label:"Track 5"});
list.addItem({label:"Track 6"});
list.addItem({label:"Track 7"});
addChild(list);
}
list.addEventListener(Event.CHANGE, itemClick);
public function itemClick() {
status_txt.text = "You selected: " + event.target.selectedItem.label;
}
}
}

Try always to do easy, you don't need the butdin class, and you can insert directly your list in the Stage and then create the document class of your project :
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Main extends MovieClip {
public function Main() {
butdin.addEventListener(MouseEvent.CLICK, btn_on_Press);
list.addEventListener(Event.CHANGE, list_on_Change);
}
private function btn_on_Press(e:MouseEvent): void {
for (var i:int = 1; i < 8; i++){
list.addItem ({ label: 'Track ' + i });
}
}
private function list_on_Change(e:Event): void {
trace('You selected : ' + e.target.selectedItem.label);
}
}
}
Hope that can help.

The code you shared will not work any way. Because you created the button class wrongly.You are trying to add list and trying accessing the textfield .It's not possible anyway.Instead you could add a document class .
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
var list:List;
public function Main() {
butdin.addEventListener (MouseEvent.CLICK, sayit);
}
private function sayit (e:MouseEvent):void
{
list = new List();
list.setSize (361,291);
list.move (421, 254);
//var i:uint;
//for (i=1; i<8; i++)
//{
//list.addItem ( { label: "Track " + i } );
//}
list.addItem ( { label: "Track 1" } );//Opens swf file 1.swf in next frame on stage
list.addItem ( { label: "Track 2" } );//Opens swf file 2.swf in next frame on stage
list.addItem ( { label: "Track 3" } );
list.addItem ( { label: "Track 4" } );
list.addItem ( { label: "Track 5" } );
list.addItem ( { label: "Track 6" } );
list.addItem ( { label: "Track 7" } );
addChild (list);
list.addEventListener (Event.CHANGE, itemClick);
}
private function itemClick ()
{
status_txt.text = "You selected: " + event.target.selectedItem.label;
}
}
}
Make sure all necessary packages imported and the button and the textfield has the instance name

Related

AS3- ReferenceError: Error #1069: Property not found

Can someone tell me why I get this error?
ReferenceError: Error #1069: Property roll_mc not found on com.usmanzubairi.theAges.TheAges and there is no default value.
at com.usmanzubairi.theAges::PirGame/rolling()
package com.usmanzubairi.theAges
{
import flash.display.MovieClip;
import flash.events.*;
import flash.media.*;
public class TheAges extends MovieClip
{
private var game:PirGame;
private var game2:PreGame;
private var game3:SupGame;
public function TheAges()
{
stage.addEventListener(MouseEvent.CLICK, startGame);
}
private function startGame(event:Event):void
{
if (event.target != player_btn)
{
removeEventListener(MouseEvent.CLICK, startGame);
game = new PirGame();
addChild(game);
}
else
{
addChild(player_mc);
player_mc.visible = true;
player_mc.play();
}
if (event.target == player_mc.tom_mc)
{
removeEventListener(MouseEvent.CLICK, startGame);
game2 = new PreGame();
addChild(game2);
}
if (event.target == player_mc.pete_mc)
{
removeEventListener(MouseEvent.CLICK, startGame);
game = new PirGame();
addChild(game);
}
if(event.target == player_mc.sam_mc)
{
removeEventListener(MouseEvent.CLICK, startGame);
game3 = new SupGame();
addChild(game3);
}
}
public function gameOver():void
{
removeChild(game);
game = null;
stage.addEventListener(MouseEvent.CLICK, startGame);
}
}
}
Here's the PirGame document class code:
package com.usmanzubairi.theAges
{
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.net.SharedObject;
public class PirGame extends MovieClip
{
public function PirGame()
{
addEventListener(MouseEvent.CLICK,rolling);
}
private function rolling (event:Event):void
{
if (event.target == MovieClip(root).roll_mc)
{
addChild(roll)
roll.visible = true;
runner_mc.visible = false;
roll.play();
}
}
}
}
Thanks.
If your roll_mc is in your PirGame symbol, and i think Pirgame class is well associated with the symbol, try modify your PirGame class a s follow:
package com.usmanzubairi.theAges
{
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.net.SharedObject;
public class PirGame extends MovieClip
{
public function PirGame()
{
addEventListener(MouseEvent.CLICK,rolling);
}
private function rolling (event:Event):void
{
trace( event.target, roll_mc );
// change MovieClip(root).roll_mc to this.roll_mc as roll_mc is on this symbol and not on the root.
if( event.target == this.roll_mc )
{
trace( 'roll_mc clicked' );
addChild( roll )
roll.visible = true;
runner_mc.visible = false;
roll.play();
}
}
}
}
if you just want the roll_mc be clickable try the following:
package com.usmanzubairi.theAges
{
import flash.utils.Timer;
import flash.events.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.net.SharedObject;
public class PirGame extends MovieClip
{
public function PirGame()
{
if( roll_mc ) roll_mc.addEventListener( MouseEvent.CLICK, rolling );
else addEventListener( Event.ADDED_TO_STAGE, _onStage );
}
private function _onStage( e:Event ):void
{
removeEventListener( Event.ADDED_TO_STAGE, _onStage );
roll_mc.addEventListener( MouseEvent.CLICK, rolling );
}
private function rolling( e:Event ):void
{
trace( 'roll_mc clicked' );
addChild( roll )
roll.visible = true;
runner_mc.visible = false;
roll.play();
}
}
}
if you don't have to re display the runner_mc you can remove it from the display list instead of make it not visible:
removeChild( runner_mc );

Variable cmodule.shine::CLibInit is not defined. AS3

I am using AS3 on Flash... I am trying to modify a .fla file which is audio recording and add a mp3 convert using ShineMP3Encoder, but when I ran the program, record and convert I always end at this error
<!-- Flash output - read from bottom to top
ReferenceError: Error #1065: Variable cmodule.shine::CLibInit is not defined. // this is the error
at fr.kikko.lab::ShineMP3Encoder/start()
at Main/encodeToMP3()
at Main/recordComplete()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at org.bytearray.micrecorder::MicRecorder/stop()
at Main/stopRecording()
-->
Here is my Code:
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
import flash.media.*;
import flash.utils.*;
import flash.display.Sprite;
import flash.media.Microphone;
import flash.system.Security;
import org.bytearray.micrecorder.*;
import org.bytearray.micrecorder.events.RecordingEvent;
import org.bytearray.micrecorder.encoder.WaveEncoder;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.ActivityEvent;
import fl.transitions.Tween;
import fl.transitions.easing.Strong;
import flash.net.FileReference;
import flash.utils.ByteArray;
import fr.kikko.lab.ShineMP3Encoder;
public class Main extends Sprite
{
private var mic:Microphone;
private var waveEncoder:WaveEncoder = new WaveEncoder();
private var recorder:MicRecorder = new MicRecorder(new WaveEncoder());
private var recBar:RecBar = new RecBar();
private var tween:Tween;
private var fileReference:FileReference = new FileReference();
private var mp3Encoder:ShineMP3Encoder;
public function Main():void
{
recButton.stop();
activity.stop();
mic = Microphone.getMicrophone();
mic.setSilenceLevel(0);
mic.gain = 100;
mic.setLoopBack(true);
mic.setUseEchoSuppression(true);
Security.showSettings("2");
addListeners();
}
private function addListeners():void
{
recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);
recorder.addEventListener(RecordingEvent.RECORDING, recording);
recorder.addEventListener(Event.COMPLETE, recordComplete);
activity.addEventListener(Event.ENTER_FRAME, updateMeter);
}
private function startRecording(e:MouseEvent):void
{
if (mic != null)
{
recorder.record();
e.target.gotoAndStop(2);
recButton.removeEventListener(MouseEvent.MOUSE_UP, startRecording);
recButton.addEventListener(MouseEvent.MOUSE_UP, stopRecording);
addChild(recBar);
tween = new Tween(recBar,"y",Strong.easeOut, - recBar.height,0,1,true);
}
}
private function stopRecording(e:MouseEvent):void
{
recorder.stop();
mic.setLoopBack(false);
e.target.gotoAndStop(1);
recButton.removeEventListener(MouseEvent.MOUSE_UP, stopRecording);
recButton.addEventListener(MouseEvent.MOUSE_UP, startRecording);
tween = new Tween(recBar,"y",Strong.easeOut,0, - recBar.height,1,true);
}
private function updateMeter(e:Event):void
{
activity.gotoAndPlay(100 - mic.activityLevel);
}
private function recording(e:RecordingEvent):void
{
var currentTime:int = Math.floor(e.time / 1000);
recBar.counter.text = String(currentTime);
if (String(currentTime).length == 1)
{
recBar.counter.text = "00:0" + currentTime;
}
else if (String(currentTime).length == 2)
{
recBar.counter.text = "00:" + currentTime;
}
}
private function recordComplete(e:Event):void
{
//trace(recorder.output.bytesAvailable)
encodeToMP3(recorder.output)
//fileReference.save(recorder.output, "recording.wav");
}
//this is the function I added
private function encodeToMP3(wavData:ByteArray):void {
mp3Encoder = new ShineMP3Encoder(wavData);
mp3Encoder.addEventListener(Event.COMPLETE, mp3EncodeComplete);
mp3Encoder.start();
}
private function mp3EncodeComplete(event : Event) : void {
trace("Done !", mp3Encoder.mp3Data.length);
}
}
}
Thanks.... :)
Mody the link type of *shineMP3_alchemy.swc* from "External" to "Merged into code" where you set the Library path for ActionScript 3.0 files

Implementing stageWebView in GestureWorks TouchSprite

I am attempting to create a component in a GestureWorks AIR application that renders a stageWebView in a touchsprite container. Given the stageWebView is not a display object is this possible?
Below is the code:
package view
{
import com.gestureworks.core.GestureWorks;
import com.gestureworks.core.TouchSprite;
import com.gestureworks.events.GWGestureEvent;
import com.modestmaps.Map;
import com.modestmaps.events.MapEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class webView extends TouchSprite
{
private var urlAddress:String = "http://google.com";
public var stageWebView:StageWebView = new StageWebView();
private var ts:TouchSprite;
public function webView()
{
super();
init();
}
private function init():void
{
ts = new TouchSprite();
ts.width = 500;
ts.height = 500;
ts.x = 200;
ts.y = 100;
ts.rotation = 45;
ts.scaleX = 0.5;
ts.scaleY = 0.5;
ts.gestureEvents = true;
ts.disableAffineTransform = false;
ts.gestureList = { "n-drag":true, "n-scale":true, "n-rotate":true };
ts.addEventListener(GWGestureEvent.DRAG, gestureDragHandler);
ts.addEventListener(GWGestureEvent.ROTATE, gestureRotateHandler);
ts.addEventListener(GWGestureEvent.SCALE, gestureScaleHandler);
if(StageWebView.isSupported == true)
{
stageWebView.stage = this.stage;
stageWebView.viewPort = new Rectangle(0,0, 500, 500);
//stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChangedHandler);
//stage.scaleMode = StageScaleMode.EXACT_FIT;
//this.stage.addEventListener(Event.RESIZE, resizeEvent);
getURL();
}
else
{
urlAddress = "StageWebView not supported";
}
ts.addChild(stageWebView as DisplayObject);
addChild(ts);
}
protected function getURL():void
{
stageWebView.loadURL(urlAddress);
//stageWebView.addEventListener(Event.COMPLETE,handleLoad);
}
No. Since StageWebView is not a display object, you can't add it to another object to be managed automatically.
You can manage it manually from the sprite--when the sprite is displayed, show the web view, when the sprite is resized, resize the web view, etc.
If your web view is covering up the entire TouchSprite once it's rendered, I'm fairly certain that your sprite won't receive gesture events--those would be handled by the native component.

AS3 to get children in Gestureworks TouchSprite working

Recently just trying around with the Gestureworks multitouch.
Here I have some problem about button inside a TouchSprite, below is my code:
package
{
import com.gestureworks.core.GestureWorks;
import com.gestureworks.core.TouchSprite;
import com.gestureworks.events.GWGestureEvent;
import com.gestureworks.events.GWTouchEvent;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Stage;
import flash.events.Event;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
public class Main extends GestureWorks
{
private var myDisplay:TouchSprite;
public function Main():void
{
super();
key = "xxx";
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
}
override protected function gestureworksInit():void
{
myDisplay = new TouchSprite();
myDisplay.gestureReleaseInertia = true;
myDisplay.gestureEvents = true;
myDisplay.disableNativeTransform = false;
myDisplay.disableAffineTransform = false;
myDisplay.mouseChildren = true;
myDisplay.gestureList = {"n-drag":true,"n-scale":true};
myDisplay.addChild(boliviaMap);
myDisplay.addChild(mapPink);
addChild(myDisplay);
myDisplay.addEventListener(GWGestureEvent.DRAG, gestureDragHandler);
myDisplay.addEventListener(GWGestureEvent.SWIPE, gestureSwipeHandler);
mapPink.addEventListener(TouchEvent.TOUCH_TAP, tapPink);
}
private function tapPink(e:TouchEvent):void
{
trace("PINK");
indicatorTxt.text = "PINK";
}
private function gestureDragHandler(event:GWGestureEvent):void
{
trace("g drag: ", event.value.dx, event.value.dy);
event.target.$x += event.value.dx;
event.target.$y += event.value.dy;
indicatorTxt.text = "g drag: " + event.value.dx + " " + event.value.dy;
}
}
}
apparently the myDisplay.mouseChildren = true; will make myDisplay not able to drag or scale anymore.
Before adding your bigMap button set the mouseChildren property of myDisplay to true:
myDisplay.mouseChildren = true;
This should pass mouseEvents to objects inside.
Also, depending on the effect you want (I'm assuming this is for a multi-touch screen of somesort), I'd suggest you should probably use a TouchEvent.TOUCH_TAP on bigMap instead of MouseEvent.CLICK(MouseEvents arent multi-touch and won't be responsive if there is some kind of touch on another part of the screen at the same time).
Edit:
Assuming boliviaMap and mapPink aren't TouchMovieClips or TouchSprites then do something like this:
myDisplay.graphics.beginFill(0x555555, 1);
myDisplay.graphics.drawRect(0,0,500,500);
myDisplay.graphics.endFill();
Then add your child assuming boliviaMap and mapPink are less than 500x500px:
myDisplay.addChild(boliviaMap);
myDisplay.addChild(mapPink);
Edit 2- A working example(for me anyways) combining TouchEvents with GWEvents:
package {
import flash.display.MovieClip;
import com.gestureworks.core.GestureWorks;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import com.gestureworks.core.TouchSprite;
import flash.display.Sprite;
import flash.events.TouchEvent;
public class Main extends GestureWorks {
public function Main() {
super();
key = "INSERT YOUR GW KEY HERE";
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
}
override protected function gestureworksInit():void
{
trace("GestureWorks has initialized");
var myTouchSprite:TouchSprite = new TouchSprite();
myTouchSprite.graphics.beginFill(0x555555,1);
myTouchSprite.graphics.drawRect(0,0,100,100);
myTouchSprite.graphics.endFill();
myTouchSprite.gestureReleaseInertia = false;
myTouchSprite.gestureEvents = true;
myTouchSprite.disableNativeTransform = false;
myTouchSprite.disableAffineTransform = false;
myTouchSprite.gestureList = {"n-drag":true, "n-rotate":true};
myTouchSprite.mouseChildren = true;
var myTappableSprite:Sprite = new Sprite();
myTappableSprite.graphics.beginFill(0xAD3059,1);
myTappableSprite.graphics.drawRect(30,30,40,40);
myTappableSprite.graphics.endFill();
myTappableSprite.addEventListener(TouchEvent.TOUCH_TAP, tappedThis);
//myTouchSprite.addChild(myTappableSprite);
myTouchSprite.addChild(myTappableSprite);
addChild(myTouchSprite);
}
public function tappedThis(event:TouchEvent){
trace("You tapped this");
}
}
}
I should also add that this will only work on a screen/device that triggers TouchEvents(if you're clicking myTappableSprite with a mouse it won't trigger the event).

1046: Type was not found or was not a compile-time constant:Button

package
{
import flash.display.MovieClip;
import flash.display.NativeWindow;
import flash.display.NativeWindowInitOptions;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.SimpleButton;
public class PencereyiGizle extends MovieClip
{
public var natWindow:NativeWindow=new NativeWindow(
new NativeWindowInitOptions());
public var pencereyiAc_Btn:Button;
public function PencereyiGizle(fro:Button)
{
pencereAc_Btn = fro;
//Pencere ekleniyor
natWindow.width = 500;
natWindow.height = 400;
natWindow.activate();
natWindow.addEventListener(Event.CLOSING,pencereyiSakla);
pencereyiAc_Btn.label = "Pencereyi Ac";
pencereyiAc_Btn.addEventListener(MouseEvent.MOUSE_DOWN,pencereyiAktifEt);
}
//pencerenin kapanmasını engelleyip pencereyi gizliyoruz.;
private function pencereyiSakla(e:Event):void
{
e.preventDefault();
natWindow.visible = false;
}
//gizlenen pencereyi tekrar aktif hale getiriyoruz
private function pencereyiAktifEt(e:MouseEvent):void
{
natWindow.activate();
}
}
}
IN AIR;
import PencereyiGizle;
var firat:PencereyiGizle= new PencereyiGizle();
addChild(firat);
and then, i get that problem "1046: Type was not found or was not a compile-time constant:Button. "
Based on what is in your imports, I think you want to use the SimpleButton class and not the Button class. (Which is a flash component)
Either that or you are missing this import
import fl.controls.Button;
Here is an artilce from adobe on the button component.
http://www.adobe.com/devnet/flash/quickstart/button_component_as3.html