• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Pass a variable from main class to a MovieClip

Explorer ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

Hello !

I have a document with main class.

I also have some movieclips which have their own class and functions.

I am trying to pass a variable from my main class to one of these MovieClips.

I tried some stuff, nothing worked.

Who can help ?

TOPICS
ActionScript

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 26, 2011 Dec 26, 2011

Match_Easy looks like a class name.  you need to use the instance name.

Votes

Translate

Translate
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

are the moveiclips instantiated in your document class?  if so, they have access to main class variables.

if the movieclips are added in the ide, they'll have to reference the root cast as a movieclip:  MovieClip(root).mainVar (if the code is on the main timeline)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

I wasn't being very clear.

My problem exactly is that, I want to run a function of my MovieClip from my MainClass.

myMovieClip.DoYourFunction(withMyClassVariable)

and in the MovieClip's class :

public function DoYourFunction(WhatVariable:String) {

}

Again sorry for not being clear.

How can I do this scenario?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

how/where is myMovieClip instantiated?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

It is put on stage on one frame.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

if that movieclip method is public, you can use:

MovieClip(root).yourmovieclipinstancename.DoYourFunction(somestring);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

It gives me :

Property Match_Easy not found on ControlUnit and there is no default value.

ControlUnit is my main Class.

Match Easy is the movieClip which is on frame 4 of my timeline and it has it's AS Linkage as Match_Easy.

If I put an instane name for it I get this error:


Type was not found or was not a compile-time constant: Match_Easy.

What can I do. I'm frustrated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

you probably have more than 1 error.  respond to each of the following:

1.  are you checking if the main timeline is on frame 4 so your movieclip exists?

2.  is your method public?

3.  show the code you're using to reference that method.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

Alright ...everything seems fine to me.

Here's the code in my Main Class :

public function BonusClicked(e:MouseEvent) {

            trace(currentFrame);

            MovieClip(root).Match_Easy.Hint(myBonus);

        }

And the code in Match_Easy :

public function Hint(WhatKind:String) {

            if (WhatKind == 'Time') {//Bonus ne kohe ...Hiqen disa sekonda.

                gameTime +=  TimeBonus;

            } else if (WhatKind == 'Score') {//Bonus ne pike ...Shtohen disa pike.

                gameScore +=  pointsForMatch;

            } else {//Bonus qe shfaq te gjithe letrat dhe me pas i kthen sic ishin.

                HintTimer = new Timer(250,2);

                HintTimer.addEventListener(TimerEvent.TIMER_COMPLETE, hideCards);//Hiqe kete me nje lloj menyre !?

                for (var i:uint = 0; i < BunchOfCards.length; i++) {

                    BunchOfCards.startFlip(BunchOfCards.cardface + 2);

                }

                function hideCards(e:MouseEvent):void {

                    for (var i:uint = 0; i < BunchOfCards.length; i++) {

                        BunchOfCards.startFlip(1);

                    }

                }

                HintTimer.start();

            }

        }

Methods are public, frame is 4 so movieclip exists.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

Match_Easy looks like a class name.  you need to use the instance name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

Sorry but it seems I did something foolish before.

I put the instance name same as the class name. :S

Sorry and thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2011 Dec 26, 2011

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines