I am learning arrays on as3 and I managed (with help from users on this website) to get my array working, but now I get a #1009 error, the error occurs when the box_MC hits finish_MC and changes to the next scene, from what I understand its happening because the array still running? not 100% sure.
Error: TypeError: Error #1009: Cannot access a property or method of
a null object reference.at
arraystut3_fla::MainTimeline/onEnterThisFrame()
You have simply forgot to remove the Event.ENTER_FRAME listener attached to your stage object which is still fired every frame, and because all elements ( objects ) used in your onEnterThisFrame function are only in your first scene ( Scene 1 ), you will still get that error.
To avoid that, you have to remove that listener like this :
if(box_MC.hitTestObject(finish_MC)) {
stage.removeEventListener(Event.ENTER_FRAME, onEnterThisFrame);
trace ("ending");
gotoAndPlay (1, "tester");
} else {
trace ("not yet");
}
Or you can remove it in the 1st frame of your 2nd scene ( tester ) :
stop();
stage.removeEventListener(Event.ENTER_FRAME, onEnterThisFrame);
Hope that can help.
Related
Working in React Native. I'm trying to declare an array and then push things to said array, but I'm getting the error TypeError: Attempted to assign to readonly property
CONTEXT:
The app prints via a thermal printer.
The print method receives an array of commands
Example:
print([{appendText: "blah"}, {
appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
}]
The print method is asynchronous and if you attempt to call the method again before the last call has finished, it errors.
Because of #2, we created a queue system that accepts a job (array of commands) and then works through the jobs synchronously.
In a React component, I'm attempting to create a job by declaring an empty array named printJob
and then pushing various commands to it. In this case, we take a snapshot of a View and then push the commands returned by the printImage method to the printJob array.
onClick={() => {
const printJob = []
viewShot.current
.capture()
.then((uri) => {
printJob.push(...printImage(uri))
})
.catch((err) => alert(err))
newPrintJob(printJob)
}
printImage returns the array of commands to print an image and cut the paper:
const CUT_PAPER = {
appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed,
}
export function printImage(uri) {
return [{ appendBitmap: uri }, CUT_PAPER]
}
So the goal is to generate the array of commands and pass that to the queue as a job. Now, I could just do newPrintJob(printImage(uri)) in the above case, which works completely fine. However, there is a particular setting the user can configure where it will need to print multiple images, one per ticket (in other words, multiple printImages). I want to consider all of that one job, hence the need to create the printJob array.
THE PROBLEM:
I'm getting an error TypeError: Attempted to assign to readonly property which seems to be triggered by printJob.push(...printImage(uri)). If I comment that line out, the error doesn't get thrown.
I don't understand why this would happen because you can call push on an array, even if it's declared as a constant. I also tried declaring it with var and let and still received the same error.
I hope I've provided enough context here. LMK if I need to add more.
Additional info:
"react": "16.13.1"
"react-native": "~0.63.3"
Turns out the issue was not pushing to the array. The issue was was trying to add the job to the queue:
newPrintJob(printJob)
...outside of the async's callback. Solution was to move the newPrintJob line into the .then block.
public class Button : MonoBehaviour {
public Material[] mButton;
Renderer rend;
// Start is called before the first frame update
void Start()
{
Debug.Log(mButton[0]);
rend = GetComponent<Renderer>();
rend.sharedMaterial = mButton[0];
}
I am getting a "Index Out of Bounds" error at the rend.sharedMaterial=mButton[0] line. It is an array of two elements. I have different materials in each of the two locations of the array. The Debug.Log accurately shows which material is in the [0] location.
Any ideas? Thanks in advance.
The comment posted by #PhilippLenssen solved the issue.
His comment:
"Can you please double-check that the error happens at the rend.sharedMaterial line, and not the Debug.Log line? (E.g. it sometimes happens that one assigns the same script to two different gameObjects accidentally -- one would now have an empty material list, thus throw an error at the Debug.Log line.) "
Once I commented out the Debug.Log(mButton[0]); line, the error cleared.
I am fetching an array of objects from an RX/JS call from an http backend. It returns an object which I am then trying to work with. I am making changes to this object using a for loop (in this example I am trying the .forEach because I have tried a number of different things and none of them seem to work.
When I run the code, I get a very weird problem. If I return the values of the properties, I get the new values (i.e. correctionQueued returns as true, etc.) but in the very next line, when I return the object, those same values are the same as the original (correctionQueued === false, etc.) HOWEVER, correctionStatus (which does not exist on the original object from http) sets just fine.
I don't understand how
array[index].correctionQueued can return true, but
array[index] returns an object with correctionQueued as false.
After the loop, the original array (checklistCopy) is identical to the object before the forEach loop, except the new property (correctionStatus) is now set, but all properties that I changed that were part of the original object remain as they were.
I have tried using a for of, for in, and .forEach. I have used the index to alter the original array, always the same result. Preexisting properties do not change, new properties are added. I have even tried working on a copy of the object in case there is something special about the object returned from rxjs, but to no avail.
checklistCopy.forEach((checklistItem, index, array) => {
if (checklistItem.crCode.isirName === correctionSetItem) {
array[index].correctionQueued = true;
array[index].correctionValue = mostRecentCorrection.correctionValue;
array[index].correctionStatus = mostRecentCorrection.status;
console.log(array[index].correctionQueued, array[index].correctionValue, array[index].correctionStatus);
console.log(array[index]);
}
}
);
I don't get an error, but I get..
Original object is:
correctionQueued: false;
correctionValue: JAAMES;
--
console.log(array[index].correctionQueued, array[index].correctionValue, array[index].correctionStatus);
true JAMES SENT
but when I print the whole object:
console.log(array[index]);
correctionQueued: false;
correctionValue: JAAMES;
correctionStatus: "SENT'; <-- This is set correctly but does not exist on original object.
console.log(array[index]) (at least in Chrome) just adds the object reference to the console. The values do not resolve until you expand it, so your console log statement is not actually capturing the values at that moment in time.
Change your console statement to: console.log(JSON.stringify(array[index])) and you should discover that the values are correct at the time the log statement runs.
The behavior you are seeing suggests that something is coming along later and changing the object properties back to the original value. Unless you show a more complete example, we can't help you find the culprit. But hopefully this answers the question about why your logs show what they show.
Your output doesn't make sense to me either but cleaning up your code may help you. Try this:
checklistCopy.forEach(checklistItem => {
checklistItem.correctionQueued = checklistItem.crCode.isirName === correctionSetItem;
if (checklistItem.correctionQueued) {
checklistItem.correctionValue = mostRecentCorrection.correctionValue;
checklistItem.correctionStatus = mostRecentCorrection.status;
console.log('checklistItem', checklistItem)
}
}
);
Simply,
I have randomly placed and moving movie clips that will call victims And I Have another set of random Moving movie clips that have an attack animation I will call them assailants.
Victims wander randomly among Assailants an at random times the Assailants will shoot out a lightning bolt movie clip to attack the victims. It is at this point I am attempting to check for a collision between the victims and the assailants lightning Bolts.
Both types are in separate array's and I have before checked an array vs an array without a problem I have also checked static object vs an array objects internal MC without an issue. However I am Stuck when checking array vs array objects internal MC.
Code:
for(var j:int=0;j<NormalBubbleArray.length;j++){
for(var k:int=0;k<LightningStormArray.length;k++){
if(NormalBubbleArray[j].hitTestObject(LightningStormArray[k]).upbolt){
trace("hit")
NormalBubbleArray.removeAt([j]);
LightningStormArray.removeAt([k]);
}
}
}
I have also Tried
if(NormalBubbleArray[j].hitTestObject(LightningStormArray[k]).upbolt)
and 10 other ways to try and write it. Still no luck not sure if its my loop or collision detection at this point. It gives no errors when running so I assume my Syntax is Ok.
Thanks In Advance.
Update: I was tinkering with it and realized I had it wrapped in a try catch so I was not seeing the error. now my issue is this.
for(var j = 0; j<NormalBubbleArray.length;j++){
for(var k = 0; k<LightningStormArray.length;k++){
if((LightningStormArray[k]).upbolt hitTestPoint(NormalBubbleArray [j]), true){
trace("hit")
(NormalBubbleArray [j]).removeEventListener(MouseEvent.MOUSE_MOVE, ChildMouse);
NormalBubbleArray.removeAt([j]);
LightningStormArray.removeAt([k]);
}
}
}
Still Compiles but when it comes time to detect I get The following error in the output.
TypeError: Error #1006: value is not a function.
at BubblesReloaded_fla::MainTimeline/CollisionControl()
Help is appreciated.. I am still tinkering with it.
Got it !
Tricky Devil.
The debuger kept pointing to the hittest line and it had nothing to do with the actual line it hilighted but what was inside the if statment that caused the issue.
var Lstormpoints:int = 0;
for(var j = 0; j<NormalBubbleArray.length;j++){
for(var k = 0; k<LightningStormArray.length;k++){
if(LightningStormArray[k].upbolt.hitTestPoint(NormalBubbleArray [j]), true){
trace("bubble is hit")
NormalBubbleArray [j].removeEventListener(MouseEvent.MOUSE_MOVE, ChildMouse);
NormalBubbleArray [j].gotoAndPlay(10)/// was (NormalBubbleArray [j]).gotoAndPlay(10) // was causing an error
NormalBubbleArray.removeAt([j]);
LightningStormArray.removeAt([k]);
}
}
}
What threw me off was that the debugger kept pointing to the if statement as the error. What I did not catch is it was trying to tell me that it was an error inside the if statement. I figured it out after some heavy tracing I Noticed that it was detecting collision but the Bubble was not acting as if it got hit giving me the illusion that it was not detecting hit. the gotoAndPlay line animates the death and sadly that was the line with the issue.. just happy I got it going.
I am cleaning up a scene in Corona and attempting to remove the event listeners in the destroy event for the scene. I've added the events in the show event for the scene, as follows:
function scene:show(event)
Runtime:addEventListener("enterFrame", onFrame)
Runtime:addEventListener("touch", onTap)
Runtime:addEventListener("collision", onCollision)
end
function scene:destroy(event)
Runtime.removeEventListener("enterFrame", onFrame)
Runtime.removeEventListener("touch", onTap)
Runtime:removeEventListener("collision", onCollision)
end
I'm getting a null pointer in the destroy event:
?:0: attempt to index field '_super' (a nil value)
stack traceback:
?: in function 'removeEventListener'
What "_super" is it trying to access, and why is it nil? I've checked and all of the functions listed above (onFrame, onTap, and onCollision) are not nil. If anyone has any idea what's going on here, please let me know!
Seems you've mistyped when calling removeEventListener.
See: Runtime . removeEventListener() vsRuntime : removeEventListener()
When you call removeEventListener with '.' (dot), then Runtime reference isn't passed implicitly as first argument to removeEventListener().