AS3 Error #1009 - timer

Please Help me, check this code :
This is output :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Bechanodroid_LatihanPendahuluan_fla::MainTimeline/tick1()[Bechanodroid_LatihanPendahuluan_fla.MainTimeline::frame3:21]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
this is my code:
import flash.utils.Timer;
import flash.events.TimerEvent;
var countDownInc:Number = 1;
var totalSecs = 10;
var countDownSecs = totalSecs;
timer.text = countDownSecs;
var time:Timer = new Timer(countDownInc*1000);
time.start();
time.addEventListener(TimerEvent.TIMER,tick);
function tick(e:TimerEvent):void{
if(countDownSecs==0){
time.stop();
score+=0;
nextPertanyaan();
countDownSecs=totalSecs;
}else{
countDownSecs=countDownSecs-countDownInc;
timer.text=countDownSecs;
}
this.removeEventListener(Event.ENTER_FRAME, tick);
}

This line:
this.removeEventListener(Event.ENTER_FRAME, tick);
Change it for this:
e.currentTarget.removeEventListener(TimerEvent.TIMER,tick);

Related

Why do my Component lost while rendering the next page?

I'm using MathJax for the first time and I did success to display some simple formule like
'a x b = c' in a quizz whith several questions.
On the first page, my formula displayed well but not the others, as you can see on the inspector the component disappear...
Here is the first question :
And the second question :
Here is the code where I am mounting the component :
function createRandomQuestions() {
var nbQuestions = 10;
var maxInt = 15;
var randomQuestions = [];
for (var i = 0; i < nbQuestions; i++) {
var randomInt1 = getRandomInt(maxInt);
var randomInt2 = getRandomInt(maxInt);
var enounceModel = "\\({" + randomInt1 + "}\\times{"+ randomInt2 + "} = \\)";
console.log(enounceModel)
var question = {
enounce: <MathJaxDisplay
enounceModel={enounceModel}/>
,
answer: randomInt1*randomInt2
}
randomQuestions.push(question);
}
CustomLogger("randomQuestions", randomQuestions, 'TableTestHome')
setQuestions(randomQuestions);
return randomQuestions;
}
And
MathJaxDisplay
is just a custom Component englobing the regex :
"\\({a}\\times{b} = \\)";
import React from 'react';
import { MathJax, MathJaxContext } from "better-react-mathjax";
const MathJaxDisplay = ({enounceModel}) => {
return (
<MathJaxContext>
<MathJax>
{enounceModel}
</MathJax>
</MathJaxContext>
);
}
export default MathJaxDisplay;
Thank you for your help

Functions in React: my function isn't working, because of 'read-only' error. Why?

I'm trying to write a function into a React component, but I am stuck with this error:
Uncaught Error: Module build failed: SyntaxError: "productMap" is read-only
Why is this happening? And how can I fix this, so I can use productMap?
Here is my function:
printReceipt() {
var products = this.props.updateBasket.products;
//create a map of products
const productMap = {};
for(let product of products) {
if(!productMap[product.id]) {
productMap[product.id] = 1;
} else {
productMap = productMap + 1;
}
}
console.log(productMap);
}
This is happening because poductMap is of type const and const cannot change through reassignment
Change it to a let or var instead
printReceipt() {
var products = this.props.updateBasket.products;
//create a map of products
let productMap = {};
for(let product of products) {
if(!productMap[product.id]) {
productMap[product.id] = 1;
} else {
productMap = productMap + 1;
}
}
console.log(productMap);
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
Use let productMap={}; instead of const.
The const declaration creates a read-only reference to a value.
Reference
use ()=> FunctionName() instead of FunctionName()
When we call the function FunctionName(), it is just executed, but when we write () => FunctionName(), then it is only called when that particular operation is performed for example onPress.
FunctionName() sometimes doesn't work, and is only read-only, using () => FUnctionName, is a good way.

server handlers in Google app script sheets not working

I get this error when trying to execute this code from the script manager menu.
Error encountered: Script function not found: function click(e) {
var app = UiApp.getActiveApplication();
app.getElementById('label').setVisible(false);
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return app;
}
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
Logger.log(row);
}
};
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "ShowUi",
functionName : "showSidebar"
}];
spreadsheet.addMenu("Script Center Menu", entries);
};
function click(e) {
var app = UiApp.getActiveApplication();
app.getElementById('label').setVisible(false);
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return app;
}
function showSidebar(e){
var ui= UiApp.createApplication()
.setTitle('My UiApp Application')
.setWidth(250)
.setHeight(300);
var button = ui.createButton("I am a button!");
var handler = ui.createServerHandler(click);
button.addClickHandler(handler);
var label =ui.createLabel('The photograph on the dashboard taken years ago...').setId('label').setVisible(false);
handler.addCallbackElement(label).addCallbackElement(button);
ui.add(label);
ui.add(button);
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return ui;
};
I'm sorry that I had to post here for probably obvious but I could not find the answer anywhere else on the internet. Any solution or alternate way i could do the same thing would be greatly appreciated. thanks!
Try something like this:
function showSidebar(e){
var ui= UiApp.createApplication()
.setTitle('My UiApp Application')
.setWidth(250)
.setHeight(300);
var label = ui.createLabel('The photograph on the dashboard taken years ago...').setId('label').setVisible(false);
ui.add(label);
ui.add(ui.createButton('I am a button!', ui.createServerHandler('onClick')).setId('button'));
SpreadsheetApp.getActiveSpreadsheet().show(ui);
return ui;
};
function onClick(e) {
var app = UiApp.getActiveApplication();
app.getElementById('label').setVisible(false);
//SpreadsheetApp.getActiveSpreadsheet().show(ui);
app.close();
return app;
};

Actionscript add object to stage from array whats from library

I try import from library to a array and after place objectsd from array to stage.
I'm new in flash and i would make a dress up game for my girlfriend.
import flash.utils.getDefinitionByName;
import flash.display.Bitmap;
import flash.display.MovieClip;
var polc1Ar:Array = new Array();
inditasFu();
function inditasFu(){
behivas();
rakdkiFu();
}
function behivas(){
for (var i=1; i!=3; i++) {
classRef:getDefinitionByName("Symbol" + i.toString()) = new getDefinitionByName("Symbol" + i.toString() as MovieClip)();
var classRef:Symbol1 = new Symbol1();
polc1Ar.push(classRef)
addChild(polc1Ar[0]);
}
}
function rakdkiFu (){
for (var i=0; i!=polc1Ar.length; i++) {
var celTargy:Bitmap = polc1Ar[i] as Bitmap ;
this.addChild(celTargy);
celTargy.x = 25*i;
celTargy.y = 45*i;
}
}
There are lots of Syntax errors in your code. Change all of your code to:
import flash.utils.getDefinitionByName;
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.BitmapData;
var polc1Ar:Array = new Array();
inditasFu();
function inditasFu(){
behivas();
rakdkiFu();
}
function behivas(){
for (var i=1; i!=3; i++) {
var ClassRef:Class = getDefinitionByName("Symbol" + i.toString()) as Class;
var classRef = new ClassRef();
polc1Ar.push(classRef)
addChild(polc1Ar[0]);
}
}
function rakdkiFu (){
for (var i=0; i!=polc1Ar.length; i++) {
var bmpData = new BitmapData(polc1Ar[i].width, polc1Ar[i].height);
bmpData.draw(polc1Ar[i]);
var celTargy:Bitmap = new Bitmap(bmpData);
this.addChild(celTargy);
celTargy.x = 25*i;
celTargy.y = 45*i;
}
}
[1] You cannot execute 'MovieClip as Bitmap' so I used Bitmap.draw() because a MovieClip is an IBitmapDrawable.
[2] You must create a class with getDefinitionByName, you cannot just create the MovieClip directly, unless you were to create very messy code. Basically, the Syntax was wrong for it.
[3] Note that this will only work if you have three Library Clips with Exported Class Names named Symbol1, Symbol2, and Symbol3.

error With changing x and y positions of movieclip using array

I'm trying to create a program using Action Script 3.0 where I click an element, click on another element, the first element goes to the second element.
This is My code:
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.display.MovieClip;
import flash.events.MouseEvent;
stop();
var Plchange:MovieClip;
var As:Array = new Array(A1,A2,A3,A4,A5,A6,A7,A8,A9);
var Bs:Array = new Array(B1,B2,B3,B4,B5,B6,B7,B8,B9);
var Cs:Array =new Array(C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12);
var Cs1:Array=new Array(C13,C14,C15,C16,C17,C18,C19,C20,C21,C22,C23,C24);
for ( var i:int =0; i<=8 ;i++)
{
As[i].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ gotoPlace(me, As[i])});
Bs[i].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ gotoPlace(me, Bs[i])});
}
for ( var Y:int =0; i<=12 ;Y++)
{
Cs[Y].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ Set(me, Cs[Y])});
Cs1[Y].addEventListener(MouseEvent.CLICK, function(me:MouseEvent):void{ Set(me, Cs1[Y])});
}
function gotoPlace(event:MouseEvent, boing:MovieClip)
{
boing = Plchange;
}
function Set(event:MouseEvent, clip:MovieClip)
{
Plchange.x = clip.x;
Plchange.y = clip.y;
}
I'm getting an error:
TypeError: Error #1010: A term is undefined and has no properties.
at NineMen_fla::MainTimeline/frame1()
where am I going wrong? Please tell me.
First, in gotoPlace you should type Plchange = boing; not vice versa. And second, you have to check if Plchange is assigned a value within function Set(). Like this:
var Plchange:MovieClip=null;
function gotoPlace(event:MouseEvent, boing:MovieClip)
{
Plchange = boing;
}
function Set(event:MouseEvent, clip:MovieClip)
{
if (!Plchange) return; // Plchange is not assigned
Plchange.x = clip.x;
Plchange.y = clip.y;
}

Resources