Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:34:29+00:00 2026-05-23T11:34:29+00:00

may i ask how can i cast a object to another type? in AS3

  • 0

may i ask how can i cast a object to another type? in AS3 i tried putting (objectType) infront of the variable but it doesnt work, below i have added objects of fishes into the child, and i am getting the fishes back out when mouse down is triggered, and then calling the fishes what to do. however i cant call the method of the custom class fish because it is a displayobject.

private function onMouseDownTriggered(e:MouseEvent):void
{
    var food:Food = new Food(this, _stageRef.mouseX, _stageRef.mouseY);
    for (var i :int = 0; i < this.numChildren; i++)
    {
        var fish : fish= this.getChildByName("fish" + i);
        fish.getFood(food);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:34:30+00:00Added an answer on May 23, 2026 at 11:34 am

    A cast in AS3 can be achieved as follows:

    var fish:Fish = Fish(this.getChildByName("fish" + i));
    
    or
    
    var fish:Fish = this.getChildByName("fish" + i) as Fish
    

    Keep in mind though that the first cast notation is more restrictive and will effectively cause runtime exceptions when cast restrictions have not been met.

    The second notation is much looser and will not cause any runtime exceptions.
    This can be quite error prone and should be handled with care.

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a trivial question, but I will ask it anyway: can updates
This may be rather noobish but I'm gonna ask anyhow. I have a class
This may not be the kind of question one should ask on StackOverflow, but
This may sound like a bit of a rhetorical question, but I ask it
This may not be a programming question, but I don't know where to ask
This may be a stupid question, but I have to ask! I have the
I'm not a DBA so this may be a stupid question but I'll ask
May be I am getting old, but I can't find it...
I'm just starting to learn OpenCV programming. May I just ask about how can
I know this may be a stupid question to ask but I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.