Loading movie with a button - actionscript-3

I am trying to load movies via buttons interaction with ActionScript 3.0. I am creating this movie from Flash CS 5.5.
I could get the first button (I called 'Preface') to work. When adding the second button, I got this error at runtime:
Scene 1, Layer 'Actions', Frame 1, Line 22 1023: Incompatible override.
Scene 1, Layer 'Actions', Frame 1, Line 22 1021: Duplicate function definition.
There dun seem to be any duplicate that could initiate any overrides:
//import flash.events.MouseEvent;
preface.addEventListener(MouseEvent.CLICK, preface1);
sq.addEventListener(MouseEvent.CLICK, sq);
function preface1(event:MouseEvent):void
{
// Start your custom code
// This example code displays the words "Mouse clicked" in the Output panel.
trace("Mouse clicked");
var preface:Preface= new Preface;
addChild(preface);
preface.removeEventListener(MouseEvent.CLICK, preface1);
// End your custom code
}
function sq(event:MouseEvent):void
{
//Get sample menus
}
Any pointers is highly appreciated.

You have an instance of a MovieClip named sq, and you declare a function with name sq. This is no longer possible to do with Actionscript 3. You have to name your function something other than sq or preface, as this name is occupied by your another MC.

Related

Drag & Drop - ActionScript3

I am developing a simple flash game - a drag and drop game for children.
I have created three animal instances which will be dragged and dropped to the correct space. I am just adding action script and am getting the following error when trying to add drag and drop functions;
Scene 1, Layer 'Actions', Frame 1, Line 10, Column 44 1119: Access of possibly undefined property startDragging through a reference with static type String.Scene 1, Layer 'Actions', Frame 1, Line 10, Column 44 1136: Incorrect number of arguments. Expected 2.
My code is as follows;
import flash.events.MouseEvent;
stop();
//set up the buttons for the puzzle pieces
Pig.buttonMode=true;
Pig.addEventListener(MouseEvent.MOUSE_DOWN.startDragging);
Pig.addEventListener(MouseEvent.MOUSE_UP.stopDragging);
function startDragging(e:MouseEvent){
trace("startDragging");
}
function stopDragging(e:MouseEvent){
trace("stopDragging");
}
Should be
Pig.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
Pig.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
MouseEvent.MOUSE_UP is a String and it doesn't have a property called startDragging. To add a listener you should pass a function reference as a second argument of addEventListener (using comma, no a dot)

Adobe Animate errors

I'm trying to create a token that will disapear when the player touches it. I created an action for the token with the following code
package
{
import flash.display.MovieClip;
public class TokenFish extends MovieClip
{
public var isToken:Boolean;
public function TokenFish()
{
isToken = true;
}
}
}
However each time I try to run the scene to test it I will get the following errors.
Scene 1, Layer 'game_Stage', Frame 1, Line 5, Column 15 1131: Classes must not be nested.
Scene 1, Layer 'game_Stage', Frame 1 1159: The return statement cannot be used in package initialization code.
Any suggestions will very much be appreciated.
I figured it out. I was trying to create the class inside of an action which adobe animate doesn't allow. I had to create it as a separate actionscript file.

submenus wont work action script 3 flash cc professional

Hi and sorry in advance I'm super new and took me like 5 hours to reach this point!
I'm working on a project to teach young and not so young how to use windows.
so far I'm almost done but I'm having trouble on making my submenus live.
Yet so far I've completed 2 mc's on flash cc 2015 professional, its a windows start button that calls all the menu or buttons like allapps, power, settings etc..
once the menu moves can give any action to the rest of the mc's allapps, power. settings etc... get "Scene 1, Layer 'actions', Frame 1, Line 16, Column 1 1120: Access of undefined property menu1_btn."
the current ac is the following:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
startbtn_mc.buttonMode=true;
dropdown_mc.buttonMode=true;
startbtn_mc.addEventListener(MouseEvent.CLICK,dropUp);
function dropUp(e:MouseEvent):void
{
var enterTween:Tween;
enterTween = new Tween(dropdown_mc,"y",Regular.easeOut, dropdown_mc.y, 15.3, 30, false);
}
menu1_btn.addEventListener(MouseEvent.CLICK, gotoMovie);
function gotoMovie(e:MouseEvent):void
{
var moviescene:MovieClip = new movie();
stage.addChild(moviescene);
}
enterTween.addEventListener(TweenEvent.MOTION_FINISH,dropUpEventListener);
}
function dropUpEventListener(e:TweenEvent):void
{
startbtn_mc.removeEventListener(MouseEvent.CLICK,dropUp);
startbtn_mc.addEventListener(MouseEvent.CLICK,dropdown);
}
function dropdown(e:Event):void
{
var enterTween:Tween;
enterTween = new Tween(dropdown_mc,"y",Regular.easeOut, dropdown_mc.y, 470, 30, false);
enterTween.addEventListener(TweenEvent.MOTION_FINISH,dropdownEventListener);
}
function dropdownEventListener(e:TweenEvent):void
{
startbtn_mc.removeEventListener(MouseEvent.CLICK,dropdown);
startbtn_mc.addEventListener(MouseEvent.CLICK,dropUp);
}
I realize there are 9 buttons to go and I'm not able to move forward.
Please help!!!!!
Layer 'actions', Frame 1, Line 16, Column 1 1120: Access of undefined
property menu1_btn.
The error messages have specific meanings and refer you to exactly where and why the error is occuring:
on Frame 1
in Layer "actions:"
on line 16
you are referencing menu1_btn
BOOM – it is undefined.
Does menu1_btn exist? Is it named something else? A great mystery.
None of us can tell just from the code you posted what is going on in your .fla file – e.g. how it is structured, what elements are in what frames, etc.
Half of programming is debugging. Tuck in.
(and it is completely unclear what this question has to do with "sub-menus")

How to create bmi calculator inside flash cs5.5 using actionscript 3.0?

I'm not very familiar with flash so this is my current problem to deal with. I've found some code but it's in actionscript 2.0, when i tried to run it in my project, it shows the following error.
Here are my errors:
1. Scene 1, Layer 'Layer 2', Frame 1, Line 6
1067: Implicit coercion of a value of type Number to an unrelated type flash.text:TextField.
Scene 1, Layer 'Layer 2', Frame 1, Line 8
1180: Call to a possibly undefined method on.
Scene 1, Layer 'Layer 2', Frame 1, Line 8
1120: Access of undefined property release.
var weight_BMI;
var height_BMI;
var BMI_FINAL;
total_BMI=Number(weight_BMI.text)/(Number(height_BMI.text)*Number(height_BMI.text));
on(release){
trace(weight_BMI.text)
trace(height_BMI.text)
trace(BMI_FINAL)
}
AS2 is very different from AS3. AS3 works by using methods (in the same way as Java, for example). See the code below as an example (note, you may need to edit/rename your fields to get it to compile)
It works by attaching a Click EventListener to your calculate button which when triggered it runs the calculateBMI method. This method then performs the calculation and prints the result to your text field.
var myBmi:TextField;
var total_BMI:Number;
function calculateBMI(e:MouseEvent):void
{
total_BMI = Number(weight_BMI.text)/(Number(height_BMI.text)*Number(height_BMI.text));
myBmi.text = String(total_BMI);
}
btnCalculate.addEventListener(MouseEvent.CLICK, calculateBMI);

Flash CS5.5 Output Error

I have been creating a hypermedia player, and i have got to a stage where it is glitching out and it is apparently a...
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at AvalancheCityHypermediaPlayer_fla::MainTimeline/fl_CustomMouseCursor()
Here is my code:
import flash.events.Event;
cust_cursor.mouseEnabled= false;
cust_cursor.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor);
function fl_CustomMouseCursor(event:Event)
{
cust_cursor.x = stage.mouseX;
cust_cursor.y = stage.mouseY;
}
Mouse.hide();
I am not sure why it is not working properly, basically when a button is hovered over it is meant to jump to frame 2 and stop, but it is jumping to that frame, and then jumping straight to frame 1 without stopping on frame 2, and stops on frame 1.
1 . Your error isn't producing a line number. You (and I) will find this invaluable for debugging; if in the Flash IDE, you can turn this on in the Publish Settings under swf preferences as a toggle titled "Permit debugging".
2 . Is this code inside a class, or in document code (e.g., Flash IDE "Actions" tab)? If it's inside a class, make sure you pass a reference of the stage to the constructor of your class and assign it to an internally persistent variable so that fl_CustomMouseCursor can address it. By default, classes have no internal way of referencing the stage, and I'm assuming that's what's producing your #1009 error.
For example, inside your class constructor...
package com.example {
public class MyClass {
private var stage;
public function MyClass(arg) {
stage = arg;
}
}
}
And outside when instantiating the class...
var myObj:MyClass = new MyClass(stage);
3 . If you want your code to stop on a frame, use stop(); or gotoAndStop()
4 . Finally, if you're compiling with Flash IDE, you can debug this and see exactly which variable in the stack the runtime environment is having issues with. You can access it from the debug menu or by compiling with control-shift-enter.