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

Math.sin(Math.PI)

Participant ,
Apr 30, 2013 Apr 30, 2013

It's a circular pre-loader. When I add the "SecondHalf" the preloader doesn't work and gives an error saying the script is causing the flash player to run slowly. How can I fix this?

This code is in:  _root.first_mc._second_mc

previewImage.onLoadProgress = function(targetMC, lBytes, tBytes) {

//FirstHalf

//This works only without "SecondHalf"

          percentDone=Math.round((lBytes / tBytes) * 100);

          _root.loaderPsnt_tx.percentDisplay.text = percentDone + "%";

//SecondHalf

//This is not working

      _root.mc_mask.clear();

      _root.mc_mask.beginFill(0xff0000, 100);

      _root.mc_mask.lineStyle(1, 0xff0000, 80);

      for (i=0; i>=c; i--) {

         x = Math.sin(Math.PI/90*i)*mask_ra;

         y = Math.cos(Math.PI/90*i)*mask_ra;

         _root.mc_mask.lineTo(x, y);

       }

      _root.mc_mask.endFill();

      c = Math.round(percentDone * (-1.84));

};

previewImage.onLoadStart = function(targetMC) {

          _root.loaderPsnt_tx._visible = _root.circle._visible = _root.mc_mask._visible = true;

          _root.circle.setMask(_root.mc_mask);

          var mask_ra:Number = (_root.circle._width / 1) * -1;

          var c:Number = 0;

          var percentDone:Number = 0;

}; 

previewImage.onLoadComplete = function(targetMC) {

          _root.loaderPsnt_tx._visible = _root.circle._visible = _root.mc_mask._visible = false;

};

TOPICS
ActionScript
1.1K
Translate
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 , May 01, 2013 May 01, 2013

mask_ra is undefined in onLoadProgress.

use:

var mask_ra:Number;

previewImage.onLoadProgress = function(targetMC, lBytes, tBytes) {

//FirstHalf

//This works only without "SecondHalf"

          percentDone=Math.round((lBytes / tBytes) * 100);

          _root.loaderPsnt_tx.percentDisplay.text = percentDone + "%";

//SecondHalf

//This is not working

      _root.mc_mask.clear();

      _root.mc_mask.beginFill(0xff0000, 100);

      _root.mc_mask.lineStyle(1, 0xff0000, 80);

  c = Math.round(percentDone * (-1.84));

  

...
Translate
Community Expert ,
Apr 30, 2013 Apr 30, 2013

c isn't defined when your loadprogress first executes.

try:

previewImage.onLoadProgress = function(targetMC, lBytes, tBytes) {

//FirstHalf

//This works only without "SecondHalf"

          percentDone=Math.round((lBytes / tBytes) * 100);

          _root.loaderPsnt_tx.percentDisplay.text = percentDone + "%";

//SecondHalf

//This is not working

      _root.mc_mask.clear();

      _root.mc_mask.beginFill(0xff0000, 100);

      _root.mc_mask.lineStyle(1, 0xff0000, 80);

  c = Math.round(percentDone * (-1.84));

      for (i=0; i>=c; i--) {

         x = Math.sin(Math.PI/90*i)*mask_ra;

         y = Math.cos(Math.PI/90*i)*mask_ra;

         _root.mc_mask.lineTo(x, y);

       }

      _root.mc_mask.endFill();

   

};

previewImage.onLoadStart = function(targetMC) {

          _root.loaderPsnt_tx._visible = _root.circle._visible = _root.mc_mask._visible = true;

          _root.circle.setMask(_root.mc_mask);

          var mask_ra:Number = (_root.circle._width / 1) * -1;

          var c:Number = 0;

          var percentDone:Number = 0;

}; 

previewImage.onLoadComplete = function(targetMC) {

          _root.loaderPsnt_tx._visible = _root.circle._visible = _root.mc_mask._visible = false;

};

Translate
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
Participant ,
Apr 30, 2013 Apr 30, 2013

Thanks Kglad.

Got rid of the error message now but still the masking is not working as expected. Any idea why? When I use this on the root and it works but it doesn't work in _root.first_mc._second_mc?

percentDone + "%"; works though.

Translate
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 ,
Apr 30, 2013 Apr 30, 2013

well, that code doesn't look like it would do anything useful.  what is it supposed to do?

create wedge-shaped mask that increases from 0 degrees to 360?

Translate
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
Participant ,
Apr 30, 2013 Apr 30, 2013

Yes.

The preloader works fine when both the code & the MCs are on the root. Is this issue related to the code being in _root.first_mc.second_mc and the preloader being on the root?

Translate
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 ,
May 01, 2013 May 01, 2013

where's your moviecliploader and listener defined and what code is used to add the listener?

Translate
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
Participant ,
May 01, 2013 May 01, 2013

Moviecliploader and listener are defined in the same frame on _root.first_mc.second_mc

var previewMCL:MovieClipLoader = new MovieClipLoader();

var previewImage:Object = {};

previewMCL.addListener(previewImage);

previewImage.onLoadProgress = function(targetMC, lBytes, tBytes) {

///doSomething

}

RefLO.onComplete = function(file:FileReference):Void {

////doSomething

          previewMCL.loadClip(imageFile,tl.targetMC);

}

Translate
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 ,
May 01, 2013 May 01, 2013

mask_ra is undefined in onLoadProgress.

use:

var mask_ra:Number;

previewImage.onLoadProgress = function(targetMC, lBytes, tBytes) {

//FirstHalf

//This works only without "SecondHalf"

          percentDone=Math.round((lBytes / tBytes) * 100);

          _root.loaderPsnt_tx.percentDisplay.text = percentDone + "%";

//SecondHalf

//This is not working

      _root.mc_mask.clear();

      _root.mc_mask.beginFill(0xff0000, 100);

      _root.mc_mask.lineStyle(1, 0xff0000, 80);

  c = Math.round(percentDone * (-1.84));

      for (i=0; i>=c; i--) {

         x = Math.sin(Math.PI/90*i)*mask_ra;

         y = Math.cos(Math.PI/90*i)*mask_ra;

         _root.mc_mask.lineTo(x, y);

       }

      _root.mc_mask.endFill();

};

previewImage.onLoadStart = function(targetMC) {

          _root.loaderPsnt_tx._visible = _root.circle._visible = _root.mc_mask._visible = true;

          _root.circle.setMask(_root.mc_mask);

         mask_ra = (_root.circle._width / 1) * -1;

          var c:Number = 0;

          var percentDone:Number = 0;

}; 

previewImage.onLoadComplete = function(targetMC) {

          _root.loaderPsnt_tx._visible = _root.circle._visible = _root.mc_mask._visible = false;

};

Translate
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
Participant ,
May 01, 2013 May 01, 2013

Thanks Kglad!!

Translate
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 ,
May 01, 2013 May 01, 2013
LATEST

you're welcome.

Translate
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