0
    private function DropFunc (e:MouseEvent):void

    {

        if(e.currentTarget.hitTestObject(Object (e.currentTarget + "Target")))
        {
            trace("good")
        }
        else{

        e.currentTarget.x = startPosX;
        e.currentTarget.y = startPosY;
        e.currentTarget.stopDrag();
        }

    }

I need to call object named currentTarget+Target in hittest object, what should i do ?

I am newbie... sorry for silly question :X

2 Answers 2

1

If I understand your question/code sample correctly, you're trying to dynamically access an instance by name.

Instead of attempting to cast it as an Object, you need to access it as a property of the parent:

private function DropFunc (e:MouseEvent):void
{

    if(e.currentTarget.hitTestObject(this[e.currentTarget.name + "Target"]))
    {
        trace("good")
    }
    else{

    e.currentTarget.x = startPosX;
    e.currentTarget.y = startPosY;
    e.currentTarget.stopDrag();
    }

}

The above example assumes that this is the parent of an object with the instance name of e.currentTarget.name + "Target".

Sign up to request clarification or add additional context in comments.

4 Comments

I tried what you said, but here is the error : Property [object MovieClip]Target not found on Stage_30 and there is no default value. at Stage_30/DropFunc(), maybe it's because that that there is nothing on the stage , i am calling it from class. (They are only in library)
I apologize for my oversight. You would want to reference the currentTarget's name. I've made an update to the code above.
Thanks, i suppose that works but another problem still exist, ReferenceError: Error #1069: Property park_mc.NoFishing_mcTarget not found on Stage_30 and there is no default value. at Stage_30/DropFunc() <<< it can't find this movieclip on the stage, I am sure that NoFishing_mcTarget does exist in park_mc (notice that park_mc is not on the stage... how can i let him see it ?)... what should i do now ?
Without a complete understanding of your project, there's no real way for me to help you debug your issue. I would have to know how you're adding objects to the display list, and how/where DropFunc is being added as an event listener.
0

you can call the property of an object with string in the following way.

objectInstance["property"].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.