Problem on hitTestObject within Classes.

Hello

I was struggling with the function hitTestObject inside Flash AS 3.0.

I'm not very experienced with ActionScript 3.0, but I tried to find an answer to this on the internet for a long time.

The problem is that it gives me either a null reference or 'the enemy' / 'The enemy' is not defined.

This is the "main.as" file which I cleaned up a bit.

package {}

import flash.display. *;

import flash.ui.Mouse;

import flash.events. *;

Game/public class extends MovieClip {}

public var enemy: enemy = new Foe (internship);

public var Combo: Number = 0;

var stageRef:MovieClip;

public void Game() {}

stage.addChild (foe);

stage.addEventListener (Event.ENTER_FRAME, hitTest);

stage.addEventListener (MouseEvent.CLICK, spawn);

}

public void spawn(e:MouseEvent) {}

trace (MouseX);

trace (MouseY);

If (Combo == 0) {}

Combo = Combo + 1;

stage.addChild (new Boom (internship));

}

ElseIf (Combo == 1) {}

Combo = Combo + 1;

stage.addChild (new Boom1 (internship));

}

ElseIf (Combo == 2) {}

Combo = Combo - 2;

stage.addChild (new Boom2 (internship));

}

}

public void hitTest (internship) {}

}

}

}

And that is the "Boom" with the hitTestObject.

package {}

import flash.utils. *;

import flash.display.MovieClip;

import flash.events. *;

import flash.display.Stage;

SerializableAttribute public class Boom extends MovieClip {}

public var stageRef:MovieClip;

public void Boom (internship) {}

stageRef = MovieClip (this.root);

this.addEventListener (Event.ENTER_FRAME, initMovement);

addEventListener (Event.ENTER_FRAME, hitTest);

this.stageRef = stageRef; clarify stageRef for instances of the enemy

This.x = mouseX;

This.y = mouseY;

this.scaleX = 0.2;

this.scaleY = 0.2;

}

public void hitTest(e:Event) {}

If (hitTestObject (stageRef.foe)) {}

trace ("OI");

removeEventListener (Event.ENTER_FRAME, hitTest);

}

If (hitTestObject (stageRef.Foe)) {}

trace ("OI");

removeEventListener (Event.ENTER_FRAME, hitTest);

//          }

}

public void initMovement(evt:Event) {}

this.scaleX += 0.2;

this.scaleY += 0.2;

This.Alpha-= 0.1;

If (this.alpha < 0) {}

stage.removeChild (this);

this.removeEventListener (Event.ENTER_FRAME, initMovement);

}

}

}

}

You'll want to probably assign an instance name of your enemy or the enemy objects and use getChildByName:

stageRef.getChildByName ("foe_name");

Tags: Adobe Animate

Similar Questions

  • Connect tigerwoods 2008 gives online we have technical problems try again within 7 days later same message please advice__

    Connect tigerwoods 2008 gives online we have technical problems try again within 7 days later same message please advice

    Hermanus Western Cape Grootballe

    Hi Grootballe,

    Since you're having problems with your golf Tiger Woods 2008 Server, obviously their server is down because they were notified.

    You are able to play offline game because the game is installed on your computer, in contrast to game online retrieves the information from the server.

    Contact the manufacturer of your game for more information

    Thank you, and in what concerns:

    Ajay K

    Microsoft Answers Support Engineer

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • problem with XML within a class

    Ok. It is a set accessor function in one of my classes. It's supposed to load an xml document in a table when I called with the address of the xml document. When I debug I get the picture but there is no data in there.

    I'm sure I'm doing something really stupid is probably very easy to spot... Sorry - I'm new on this!

    Thank you very much!

    (I've included the code and the xml file in the code so you can see what I'm aiming to...)

    In the call from the bottom of the managers, members of the class are out of reach. You can solve this problem in several ways. In the code that you have posted, you can use a local reference to the class (the current object). In other cases, you can use the delegate class.

  • problem of scope within the class with delivery

    Hello.. I have a class in which there are properties (IE - _myColor).

    Now suppose in my class, I have a defined delivery function...

    IE

    targetMc.myBtn.onPress = function (): Void {}
    trace ("the value is:" + _myColor);
    }

    Now obviously this won't work because it is out of reach.

    What is the right way to access the property of said of the delivery which resides IN the class file as well?

    Thank you!

    You can use a local reference to the current object or use the delegate class. See examples attached.

  • Creating Windows dvd with the problem of the "invalid class string".

    When you try to burn a file to a dvd using windows dvd creation, I received a message 'tring class not valid' when burning, and the disc has been ejected. What does the message mean? How to fix?

    Hi KEVINQUACH,

    1. When you have the startup problem?

    2. you remember to make changes to the computer before this problem?

    3 - is this happen when you try to burn any type of particular file?

    You can check out the following link and try the steps suggested by Aziz N Support Engineer on December 2, 2009, and check if this may help.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-pictures/cannot-create-dvdinvalid-class-string/24d00965-F971-4982-A440-8bb01fc0db01

    Hope this information is useful.

  • Problem call for a class of jre7 to NYI

    Hello
    We have a class in java 7 and will need to loaded from native code. The system has already load some classes in java 6 with JNI, in need of an upgrade. I install the new JDK, change the include directories and link references in my VC project. Everything was fine, until he had to start the NYI jre7... When calling the JNI_CreateJavaVM, send us version NYI vm_args.version parameter, but do not have a definition for a newer version than the 1.6.

    JavaVMInitArgs vm_args;
    ...
    vm_args.version = JNI_VERSION_1_6;
    vm_args.nOptions = 2;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = 0;

    int ret = JNI_CreateJavaVM (& jvm, (void *) & env, & vm_args);

    Running the program, when JNI method calls "FindClass" from a class of jre7, the jvm throws an exception UnsupportedClassVersionError . The exception is clear, I use a class that does not support the Java virtual machine, to be a version newer than it.

    The problem: How to start, NYI, a JAVA virtual machine that supports the jre7 classes? I tried searching, but can't find any reference for this. Is it possible? The JNI library supports the jre7?


    Concerning


    PS Sorry for my English "Brazilian".

    Noting to do with JNI. You are running via a JAVA 1.6 virtual machine again. You seem to have mixed up 1.7 classes with a JVM 1.6 somehow.

  • problem between objects of class

    well, I'm a huge refactoring ActionScript file and so tried to move some functions in their own classes.  Why does this work?  I have a function in my primary class:

    // ...


    private var testBlock:Sprite;


    public Function testingINT() {}

    testBlock = new Sprite();

    var TB = new TAPATTesting();

    testBlock = TB.makeTestBlock ();

    TAPATContainer.addChild (testBlock);

    }

    ... testingINT() is called away

    and then, the class TAPATTesting is here:

    package com.bpi.tapat

    {

    import flash.display. *;

    import flash.text.TextField;

    import flash.text.TextFieldAutoSize;

    import flash.text.TextFormat;

    public class TAPATTesting { }

              

    public var testBlock:Sprite;

    public var test1TXT:TextField;

    public var test2TXT:TextField;

    public var test3TXT:TextField;

    public var test4TXT:TextField;

    public var test5TXT:TextField;

    public var test6TXT:TextField;

    public var test7TXT:TextField;

              

    public function TAPATTesting ():void {}

                   

              }

              

    public function makeTestBlock (): Sprite {}

                   

    var formatTest: TextFormat = new TextFormat();

    formatTest.font = "Monaco";

    formatTest.color = 0xCCCCCC;

    formatTest.size = 10;

                   

    testBlock = new Sprite();

                   //

                   var textX = 50;

                   var textY = 270;

    test1TXT = new TextField();

    test1TXT.autoSize = TextFieldAutoSize.LEFT;

    test1TXT.defaultTextFormat = formatTest;

    test1TXT.x = textX;

    test1TXT.y = textY;

    testBlock.addChild (test1TXT);

                   //

    test2TXT = new TextField();

    test2TXT.autoSize = TextFieldAutoSize.LEFT;

    test2TXT.defaultTextFormat = formatTest;

    test2TXT.x = textX;

    test2TXT.y = textY + 20;

    testBlock.addChild (test2TXT);

                   //

    test3TXT = new TextField();

    test3TXT.autoSize = TextFieldAutoSize.LEFT;

    test3TXT.defaultTextFormat = formatTest;

    test3TXT.x = textX;

    test3TXT.y = textY + 40.

    testBlock.addChild (test3TXT);

                   //

    test4TXT = new TextField();

    test4TXT.autoSize = TextFieldAutoSize.LEFT;

    test4TXT.defaultTextFormat = formatTest;

    test4TXT.x = textX

    test4TXT.y = textY + 60;

    testBlock.addChild (test4TXT);

                   //

    test5TXT = new TextField();

    test5TXT.autoSize = TextFieldAutoSize.LEFT;

    test5TXT.defaultTextFormat = formatTest;

    test5TXT.x = textX;

    test5TXT.y = textY + 90;

    testBlock.addChild (test5TXT);

                   //

    test6TXT = new TextField();

    test6TXT.autoSize = TextFieldAutoSize.LEFT;

    test6TXT.defaultTextFormat = formatTest;

    test6TXT.x = textX;

    test6TXT.y = textY + 110;

    testBlock.addChild (test6TXT);

                   //

    test7TXT = new TextField();

    test7TXT.autoSize = TextFieldAutoSize.LEFT;

    test7TXT.defaultTextFormat = formatTest;

    test7TXT.x = textX;

    test7TXT.y = textY + 140;

    testBlock.addChild (test7TXT);

                   

                   return testBlock;

              }

         }

    }

    So, therefore, I would that testBlock in the primary class would have the Sprite testBlock of the TAPATTesting passed to him.  The problem arises here in another function of the primary class:

    private Function testReport() {}

                        

    testBlock.test1TXT.text = ' # effect: " + currentStim + ' / ' + numberStims;"»

    testBlock.test2TXT.text = ' stem length: " + stimDuration;"»

    testBlock.test3TXT.text = ' inter-stim int: " + interStimInterval;"»

    testBlock.test4TXT.text = "target freq:" + targetFrequency; "»

         //

    testBlock.test5TXT.text = ' stem angle: " + stimAngle;"»

    testBlock.test6TXT.text = ' stim dist: ' + stimDistance;

         //

    testBlock.test7TXT.text = ' user evaluation: " + userResponseTime + "ms";". "

    }

    I get this same error on each of these lines:

    Several markers to this line:

    -1119: access to property may be undefined test7TXT through a reference with static type flash.display:Sprite.

    Why can't I access the Sprite testBlock children?

    That's because TestBlock is a Sprite, and a Sprite is not a property named "test7TXT".

    You can still access them by doing something like the following:

    -Give the textfield object a name

    test7TXT = new TextField();

    test7TXT.name = "test7TXT";

    test7TXT.AutoSize = TextFieldAutoSize.LEFT;

    test7TXT.defaultTextFormat = formatTest;

    test7TXT.x = textX;

    test7TXT.y = textY + 140;

    testBlock.addChild (test7TXT);

    -Access to the textfield object using its name

    TextField (TestBlock.getChildByName ('test7TXT')) .text = "assessment of users...". » ;

    Note that getChildByName returns the object as a DisplayObject, you will need to cast to a TextField.

    I hope this helps.

  • Problems with Apple in class

    We have a classroom set of successful however iPads Meraki.  We have imported the information class and the teachers of the school of Apple.  Watching iPads I can see that the profile of education has been eliminated from the MDM, but the teacher still cannot start the App class.  Suggestions for troubleshooting?

    Even if we do not Meraki, (we use OS X Profile Manager), we can get the training profiles to load on our iPad pros.  Loads on everything...

    suggest post you the link for the deployment of mMeraki: https://documentation.meraki.com/SM/Profiles_and_Settings/Configuring_an_Educati on_Payload_for_Apple_Classroom

  • Problem with the Screen class

    Hello

    Please anyone suggest me that I had made an application for blackberry strom 9500 when I got extends the class of devices back button screen is disabled automatically. and when I extends the class screen it works correctly.

    I don't think that the class screen itself has the feature to close the screen when you press the ESC by default. If it isn't and you want to use it, you can pass the DEFAULT_CLOSE style to it.

    public class MyScreen extends Screen {     MyScreen(Manager m)     {          super(m, Screen.DEFAULT_CLOSE);      }
    
        protected void sublayout(int width, int height) {        // Add sublayout logic    }}
    

    Documentation: http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/Screen.html#DEFAULT_CLOSE

    Is there a reason that you are using the Screen as opposed to screen or full screen class?

  • Problem with States within the composition on the subpages only

    I use a composition to create and menu/fly on boxes of content. So far, it it show I want. The problem is when I go to another page in the site, the styles do not stick to the menu/composition States.

    It is very obvious if you go to this link:

    Home

    Fly over the AREAS of PRACTICE and then click on INJURY. Once on the page of the injury, you can see that the applied styles do not stick on the 'normal' State of the menu.

    It is meaningless since it's the same master page, that I use for the home page and States and the styles are there.

    I appreciate the help that anyone may be able to offer!

    Thank you!

    Hmm, if you wish you can send me your .muse file in a private message and I'll have a look in a bit. If you do, please DO NOT send any personal login or password. Just the .muse file is all that is necessary.

  • Extend the child problem in java Applet - class not loading only class parent

    I have a situation like this
    A class extends the class B
    The class A and class B have its own main functions...
    Class A calls the functions of category B


    I respected and run the code, it works fine as stand alone... in fact like a Jar... Then too, everything works fine...

    ...

    BT when I called the jar in a HTML through Code of Applet... . Only the class B works directly...

    I added the category to the Applet CODE tag like this

    "< CODE ="A.class APPLET"ARCHIVE =" A.jar "WIDTH ="100% "HEIGHT ="100% ">

    but its class B still recharges directly...

    deleted the cache and tried in all ways, I know...

    To check, I removed the main function in class A and is once again the jar file and loaded...
    Always it directly loads the class B...

    But if I removed the main function of the class B the applet displays error...


    Add a message in the main function of class a... .He showing nt not in java web console, but shows the CMD line...


    DNT know what to do... .im a newbee... So I hope I missed something every important in coding...

    NB: is what I extended a VNCViewer application and it loads the screen of a remote computer by default...
    I just needed to add two buttons so that I can switch between two machines through the browser...

    Published by: 814747 on November 23, 2010 01:18... Sorry for the spelling mistakes...

    What is the main function? This is an applet. Applets do not have the main functions.

  • problem with the TextSnapshot class

    someone can help me. I m stuck on this problem. I am not able to highlight the text to the second click. There is no redirect when I m trying to clean next time. to check the output problem please enter 'hot' in the text box and click the button, you'll see the text highlighted. but next time whent, you try to click on which he he's not showing any result.

    Please help me it is very urgent...

    var my_snap:TextSnapshot;

    S1.onRelease = function() {}
    my_snap = odd_img.getTextSnapshot ();
    hltextodd (St.Text, my_snap);
    };
    //******************set focus***************
    hltextodd = function (txt:String, wink: TextSnapshot) {}
    var fnd_arr = new Array();
    var start_pos:Number = 0;
    start_pos = snap.findText (start_pos, txt, true);
    found = 0;
    While (start_pos > 0) {}
    found = found + 1;
    [found] fnd_arr = start_pos;
    var finalB:Number = start_pos + txt.length;
    snap.setSelected (start_pos, finalB, true);
    trace (start_pos +', ' + finalB);
    start_pos += txt.length;
    start_pos = snap.findText (start_pos, txt, false);
    }

    };

    "to run this script adds a text of entry in scene with the name" "st ' and button with"s1 " and a clip with static text " TextSnapshot example, TextSnapshot example, TextSnapshot example, TextSnapshot example, TextSnapshot example TextSnapshot, TextSnapshot example TextSnapshot, TextSnapshot example, TextSnapshot example, TextSnapshot example, TextSnapshot example "

    Help, please... It is urgent. ..

    Thanks in advance.

    Thank you so much dear...

  • Small problem with external video class does not

    It's my first external class and I am not able to see the video once I publish the swf file

    package {}

    import flash.display.Sprite;

    import flash.net.NetConnection;

    to import flash.net.NetStream;

    import flash.media.Video;

    import flash.display.MovieClip;

    SerializableAttribute public class FLVPlayerBasic extends Sprite {}

    public void FLVPlayerBasic() {}

    Build NetConnection

    var nc:NetConnection = new NetConnection();

    NC. Connect (null);

    Flash is looking for an onMetaData method

    Route all calls to an object

    var metaObject:Object = new Object();

    metaObject.onMetaData = onMetaData;

    Build NetStream and connect to the flow through the connection

    var ns:NetStream;

    NC = new NetStream (nc);

    ns.play ("http://www.someurl.com/video/video.flv" "");

    Route all calls to the metaObject NetStream onMetaData

    NS.client = metaObject

    Build a video object with dimensions

    Video: var video = new video (320, 240);

    Attach the video in the NetStream and added to the display list

    video.attachNetStrea (ns);

    addChild (video);

    }

    private void onMetaData(data:Object):void {}

    }

    }

    }

    the class file whose code display you in your first message MUST be named: FLVPlayerBasic

    and if you click on an empty part of the scene and look in the properties panel, FLVPlayerBasic must appear in the document class.

  • Small problem with the tween class?

    Hey everyone, I have a site that incorprerates several different interpolations, interpolation, running on a timer in the main movie(scrolling text), another developed with a button click (scrolling images) in a film that is loaded into the main movie. My problem is that tweens sometimes freeze, especially the scrolling text and from time to time, random images, interpolation of images scroll freezes. I should mention that I have several different EventListeners in the background to mouse clicks, and I have small (15 k) SWFs loaded into the film every 3.5 seconds. If anyone knows why the tweens freeze sometimes? could it have something to do with the loading and the EventListeners, or I have to live with?

    Thank you for reading and suggestions that you may have;


    The draft of the site is www.sunnysideosc.ca (select Gallery > pictures)

    Interpolations of freezing is usually caused by the instance of Tween getting the garbage collector. You must have the persistence of a reference to the Tween to prevent it of to GC would be. In other words, if you do this:

    new Tween(obj,'x',etc...)
    

    While Tween will get destroyed the tracks of time following GC. Instead, follow these steps:

    tween = new Tween(obj,'x',etc...)
    

    steerage "would be a property of the object in scope when the Tween is created.

    Also, you can create the Tween instance once at the beginning and assign to a property and use Tween.continueTo () to make the animations.

  • Problem sending event with Classes

    I have a custom Timer class that displays an alert of inactivity after 3 minutes. The user can then choose 'Yes' if they're still edit a document or a "' if they are done. If they do not respond to 2 minutes of the alert it considers 'no '.

    A 'yes' refreshes the timer and closes the alert.
    A 'no' kicked out of the State of change in the component that is called from the timer.

    The logic of the timer works fine, but it doesn't seem to be sending the event to the element that so called by clicking 'no' (or is idle) does nothing. I feel I'm missing something really simple or just misunderstand the function of eventDispatcher. Advice please?

    Code Timer class:

    Timer/public class extends Sprite
    {
    private var threeMinuteTimer:Timer;
    private var twoMinuteTimer:Timer;

    public void LockTimer()
    {
    creates a new three Timer
    threeMinuteTimer = new Timer(1000, 180);
    twoMinuteTimer = new Timer(1000, 120);

    designates earphones for the period of integration and completion events
    threeMinuteTimer.addEventListener (TimerEvent.TIMER, __ontick__);
    threeMinuteTimer.addEventListener (TimerEvent.TIMER_COMPLETE, onTimerComplete);

    twoMinuteTimer.addEventListener (TimerEvent.TIMER, __ontick__);
    twoMinuteTimer.addEventListener (TimerEvent.TIMER_COMPLETE, onTimerCompleteB);

    starts the timer ticking
    threeMinuteTimer.start ();
    }

    public void refresh (): void {}
    Restart (threeMinuteTimer);
    twoMinuteTimer.reset ();
    }
    private void onTick(evt:TimerEvent):void {}

    private void onTimerComplete(evt:TimerEvent):void {}
    trace ("first timer");
    Alert.Show ("you've been idle for several minutes. You always edit this record? ","Inactivity Alert", Alert.YES |" Alert.NO, alertListener, null, null, Alert.YES);
    twoMinuteTimer.start ();
    }

    private void onTimerCompleteB(evt:TimerEvent):void {}
    trace ("second timer'");
    Alert.Show ("TIME of ', 'Inactivity alert', Alert.OK");
    dispatchEvent (new Event ("timeUp", true));
    }

    private void restart(tim:Timer):void {}
    Tim.Reset ();
    Tim.Start ();
    }


    private void alertListener(eventObj:CloseEvent):void {}
    Check if the YES button was pressed.
    If {(eventObj.detail is Alert.YES)
    Refresh();
    } else {}
    leave edit mode
    Alert.Show ("TIME of ', 'Inactivity alert', Alert.OK");
    dispatchEvent (new Event ("timeUp", true));
    }
    }
    }

    The component code:

    private var theTimer:LockTimer;
    private void initializeHandler(event:Event):void {}
    addEventListener ("timeUp", timeUpHandler);
    }
    private void timeUpHandler(event:Event):void {}
    Alert.Show ("TIME of ', 'Inactivity alert', Alert.OK");
    editDone();
    }

    So here's what I had to do to make this work:

    1. I had to fix the theTimer rather than the component listener
    2. I had to launch the manufacturer outside the service timer
    3. I had to call the Manager of the MXML component initialization function

    Here's the code revised (with excess cutting)


    http://www.Adobe.com/2006/mxml"width ="780"height ="515"liveDragging ="true"creationComplete =" initializeHandler () ">"
    ......
    ......
    ......

    Import mx.controls.Text;
    Import mx.rpc.events.FaultEvent;
    Import mx.rpc.events.ResultEvent;
    Import mx.controls.Alert;
    import classes. Timer;

    public static millisecondsPerMinute:int const = 1000 * 60;
    public static millisecondsPerHour:int const = 1000 * 60 * 60;
    public static millisecondsPerDay:int const = 1000 * 60 * 60 24;

    IMPORTANT! ////////////////
    private var theTimer:LockTimer = new LockTimer();
    private function initializeHandler (): void {}
    theTimer.addEventListener ("timeUp", timeUpHandler);
    }
    private void timeUpHandler(event:Event):void {}
    editDone();
    }

    private void refreshLock(theLock:int):void {}

    var theTime:Date = new Date();
    {if(theLock==1)}
    theTimer.refresh ();
    theTime.setTime (theTime.getTime () + (millisecondsPerMinute * 5));
    } else {if(theLock==0)
    theTime.setTime (theTime.getTime ());
    } else {}
    return;
    }
    Form1.request.firmlockedTime = String (theTime.valueOf ());
    Form1.request.firmisLocked = String (theLock);
    }

    private function editIt (): void {}
    see if it is edited
    {if (checkLock ())}
    If its being edited to send a message
    Alert.Show ("this disc is currently being edited by another user. Please try again later.', "Record locked", mx.controls.Alert.OK);
    } else {}
    theTimer.startMe ();
    refreshLock (1);
    Form1.send ();
    currentState = "AdminEdit;
    }
    }
    private function editDone (): void {}
    refreshLock (0);
    Form1.send ();
    currentState = "Admin";
    }

    ]]>

    ......
    ......
    ......

Maybe you are looking for

  • How can I insert a new blank page immediately after a proposed page

    I'm trying to change an iBook of 147 pages, and I want to add a new blank page immediately after page 73.  I tried ctrl-click on the page, but the new page is added at the end of the chapter, which is obviously not where I want to.

  • Problems of implementation of new MacBooks

    Hello I have just taken delivery of a 2015 12 '' Macbook today.  I'm having some trouble setting up although.  I hope someone can help me. When you try to enter my apple ID in the initial implementation of the Macbook (which is certainly correct that

  • Equium L10-142 - battery won't load

    I've had my Equium L10-142 for about four years now, and I know that it is long enough for a laptop. Last year I had problems with the battery that refuses to load at all and more in the past months, the cable ca now seems to be worse and worse. Now

  • MJB: FF 3.6.6 falls down repeatedly, even when idle

    [My apologies, I clicked on the incorrect URL and close the previous thread by mistake.] I have FF 3.6.6 to random crashing when I am still doing nothing. I have two websites open normally, none of them use Flash or Adobe plug-ins. A self-actualizati

  • VI read-only when opened by another developer?

    We have several developers working on the same project and I want to avoid 2 developers edition vi even at the same time. Is it possible, as in Excel, to make a 'read only' vi to others as soon as it is opened by a developer?