6 Replies Latest reply on Dec 15, 2006 5:05 PM by kglad

    asfunction, cursor states, and moviclips...oh my

    flashWannaBe
      Hello all. I've ran into a bit of a snag and I'm thinking the obvious is sitting right in front of me...

      I have a dynamic movieclip that is created to serve as a container for a dynamically created textfield. The textfield has html text. Within that html text is an asfunction to call a method. Code is posted below:

      MovieClip(this.createEmptyMovieClip("textOneContainer_mc", this.getNextHighestDepth());
      TextField(textOneContainer_mc.createTextField("textOneField", textOneContainer_mc.getNextHighestDepth(), 10, 10, 300, 30));

      // Method triggered from asfunction call from html text
      textOneContainer_mc.launchGlossary = function(arg){
      trace("Launch Glossary Method Hit, Glossary Word: "+arg);
      }

      textOneContainer_mc. textOneField.html = true;
      textOneContainer_mc. textOneField.htmlText = htmlString_str;

      Now the issues are:
      1. if applied, textOneContainer_mc onRollOver, onRollOut, onRelease, and etc seem to not allow the asfunction to be called
      2. i'm using custom cursors, which work fine...however, the system hand cursor appears over the word I have linked via asfunction. I've tried using the useHandCursor = false MovieClip property, but it still appears.

      I hope this makes sense, i'm a little dumbfounded on this one. The last thing I want to do is to do a split on the html text and put each word in it's own MovieClip just to achieve what the asfunction already does.
        • 1. Re: asfunction, cursor states, and moviclips...oh my
          kglad Adobe Community Professional & MVP
          the first few lines of your code look like actionscript, but, i doubt, that code would compile and it certainly wouldn't do anything. copy and paste your code.

          but once you correct your code you're still going to have a problem: you can't define mouse handlers for a parent movieclip and expect a child textfield to detect mouse events. the parent movieclip will intercept the mouse events.

          to remedy, either don't use a parent movieclip, don't use mouse handlers for your parent movieclip or use a hitTest and various mouse state detectors to fake rollover, rollout and onrelease handlers.

          • 2. Re: asfunction, cursor states, and moviclips...oh my
            flashWannaBe Level 1

            // Store Text and Audio Data From XML
            var pagetext_xmlnodeOne:XMLNode = matchSiblingNode(_parent.currentPage_xmlnode.firstChild,"instructionalTextOne");
            var pagetext_xmlnodeTwo:XMLNode = matchSiblingNode(_parent.currentPage_xmlnode.firstChild,"instructionalTextTwo");
            var swf_xmlnode:XMLNode = matchSiblingNode(_parent.currentPage_xmlnode.firstChild,"externalSwfFile");
            var swfLocation:String = swf_xmlnode.attributes.swfFilePath;
            var textOneAudio:String = pagetext_xmlnodeOne.attributes.audioPath;
            var textTwoAudio:String = pagetext_xmlnodeTwo.attributes.audioPath;
            var titleText:String = _parent.currentPage_xmlnode.attributes.title;
            var textOne_str:String = pagetext_xmlnodeOne.firstChild.nodeValue;
            var textTwo_str:String = pagetext_xmlnodeTwo.firstChild.nodeValue;

            trace("///// Title Text: "+titleText+" /////////////////////////////////////////////////////////");

            //Loads SWF File
            function loadSWF(externalSwfLocation:String){
            var swfFile:Boolean = false;
            //Object to Load SWF File
            var mcLoader:MovieClipLoader = new MovieClipLoader();
            var mclListener:Object = new Object();
            if (externalSwfLocation != undefined){
            if (externalSwfLocation.indexOf(".swf") > 0){
            swfFile = true;
            trace(".SWF Path: "+externalSwfLocation+" Target Clip: "+mediaSWF_mc);
            mcLoader.loadClip(externalSwfLocation,mediaSWF_mc);
            image_mc = mediaSWF_mc;
            }
            } else {
            //In the Event There is No SWF File, loadText Method Called
            trace("No SWF File to Load, loadText Method Being Called");
            loadText(textOne_str,textTwo_str,textOneAudio,textTwoAudio);
            }

            mcLoader.addListener(mclListener);
            mclListener.onLoadComplete = function(){
            trace(".swf Loaded Successfully");
            trace("loadText Method Being Called");
            loadText(textOne_str,textTwo_str,textOneAudio,textTwoAudio);
            }
            mclListener.onLoadInit = function(target_mc:MovieClip){
            //Adjust SWF
            var pictH:Number = target_mc._height;
            var pictW:Number = target_mc._width;
            var pictX:Number = target_mc._x;
            var pictY:Number = target_mc._y;
            if (swfFile){
            pictH = Number(swf_xmlnode.attributes.swfHeight);
            pictW = Number(swf_xmlnode.attributes.swfWidth);

            if(swf_xmlnode.attributes.swfX!=undefined){
            pictX = Number(swf_xmlnode.attributes.swfX);
            } else { pictX = 0 };

            if(swf_xmlnode.attributes.swfY!=undefined){
            pictY = Number(swf_xmlnode.attributes.swfY);
            } else { pictY = 0 };
            }
            //Adjust to New SWF Size and _x/_y Cooordinates
            mediaSWF_mc._width = pictW;
            mediaSWF_mc._height = pictH
            mediaSWF_mc._x = pictX;
            mediaSWF_mc._y = pictY;
            mediaSWF_mc._alpha = 0;
            }
            }

            // loadText Method
            // Creates Movieclips to Store Textfield Data
            function loadText(textOne_str:String, textTwo_str:String, textOneAudio:String,textTwoAudio:String){
            if(pagetext_xmlnodeOne.attributes._y!=undefined){
            var txtOneY_num:Number = pagetext_xmlnodeOne.attributes._y;
            } else {
            var txtOneY_num:Number = 0;
            }
            var txtOneBlock:String = pagetext_xmlnodeOne.attributes.textBlock;
            if(textOne_str!=undefined){
            var vlaInstrOneTxt_mc = MovieClip(this.createEmptyMovieClip("vlaInstrOneTxt_mc", this.getNextHighestDepth()));
            var vlaInstrOne_txt = TextField(vlaInstrOneTxt_mc.createTextField("vlaInstrOne_txt", vlaInstrOneTxt_mc.getNextHighestDepth(), 8, txtOneY_num, 0, 0));
            var vlaInstrOneFld = vlaInstrOneTxt_mc.vlaInstrOne_txt;
            vlaInstrOneFld.autoSize = "left";
            vlaInstrOneFld.embedFonts = true;
            vlaInstrOneFld.selectable = false;
            vlaInstrOneFld.multiline = true;
            vlaInstrOneFld.border = false;
            vlaInstrOneFld.html = true;
            vlaInstrOneFld.htmlText = textOne_str;
            vlaInstrOneTxt_mc.enabled = false;
            vlaInstrOneTxt_mc._alpha = 0;
            }

            vlaInstrOneTxt_mc.launchGlossary = function(arg){
            trace ("You clicked me!Argument was "+arg);
            }

            if(pagetext_xmlnodeTwo.attributes._y!=undefined){
            var txtTwoY_num:Number = pagetext_xmlnodeTwo.attributes._y;
            } else {
            var txtTwoY_num:Number = 0;
            }
            var txtOneBlock:String = pagetext_xmlnodeOne.attributes.textBlock;
            if(textTwo_str!=undefined){
            var vlaInstrTwoTxt_mc = MovieClip(this.createEmptyMovieClip("vlaInstrTwoTxt_mc", this.getNextHighestDepth()));
            var vlaInstrTwo_txt = TextField(vlaInstrTwoTxt_mc.createTextField("vlaInstrTwo_txt", vlaInstrTwoTxt_mc.getNextHighestDepth(), 8, txtTwoY_num, 0, 0));
            var vlaInstrTwoFld = vlaInstrTwoTxt_mc.vlaInstrTwo_txt;
            vlaInstrTwoFld.autoSize = "left";
            vlaInstrTwoFld.embedFonts = true;
            vlaInstrTwoFld.selectable = false;
            vlaInstrTwoFld.multiline = true;
            vlaInstrTwoFld.border = false;
            vlaInstrTwoFld.html = true;
            vlaInstrTwoFld.htmlText = textTwo_str;
            vlaInstrTwoTxt_mc.enabled = false;
            vlaInstrTwoTxt_mc._alpha = 0;
            }

            var vlaInstrText_fmt:TextFormat = new TextFormat();
            vlaInstrText_fmt.font = "VAGRoundedRegular";

            vlaInstrOneFld.setTextFormat(vlaInstrText_fmt);
            vlaInstrTwoFld.setTextFormat(vlaInstrText_fmt);

            // Make Sure Text Stays Within Bounds
            if(pagetext_xmlnodeOne.attributes.textBlock == "Left"){
            if(vlaInstrOneFld._width > 375){
            vlaInstrOneFld.wordWrap = true;
            vlaInstrOneFld._width = 375;
            }
            } else {
            if(vlaInstrOneFld._width > 670){
            vlaInstrOneFld.wordWrap = true;
            vlaInstrOneFld._width = 670;
            }
            }

            if(pagetext_xmlnodeTwo.attributes.textBlock == "Left"){
            if(vlaInstrTwoFld._width > 375){
            vlaInstrTwoFld.wordWrap = true;
            vlaInstrTwoFld._width = 375;
            }
            } else {
            if(vlaInstrTwoFld._width > 670){
            vlaInstrTwoFld.wordWrap = true;
            vlaInstrTwoFld._width = 670;
            }
            }

            // Call Transitions Clip for TextFields
            trace("All Textfield Clips Loaded, Transitions and Audio Will Now Take Place");
            transitionInFirstTxtClip();
            }

            // Apply Transitions Clip to First TextField
            function transitionInFirstTxtClip(){
            if(textOne_str!=undefined){
            fadeIn(vlaInstrOneTxt_mc, 7, this, "readFirstAudioClip");
            } else {
            trace("No Instructional Text 1 Found, calling readFirstAudioClip");
            readFirstAudioClip();
            }
            }

            // Play Audio Related to First TextField
            function readFirstAudioClip(){
            if(textOneAudio!=undefined){
            playSFX(textOneAudio, this, "nextClipTransition");
            vlaInstrOneTxt_mc.enabled = true;
            } else {
            trace("No Instructional Text 1 Audio File Found, calling nextClipTransition");
            nextClipTransition();
            }
            }

            // Apply Transtions Clip to Second TextField
            function nextClipTransition(){
            if(textTwo_str!=undefined){
            fadeIn(vlaInstrTwoTxt_mc, 7, this, "readSecondAudioClip");
            } else {
            trace("No Instructional Text 2 Found, calling readSecondAudioClip");
            readSecondAudioClip();
            }
            }

            /// Play Audio Related to Second TextField
            function readSecondAudioClip(){
            if(textTwoAudio!=undefined){
            playSFX(textTwoAudio, this, "displaySwfFile");
            vlaInstrTwoTxt_mc.enabled = true;
            } else {
            trace("No Instructional Text 2 Audio File Found, calling displaySwfFile");
            displaySwfFile();
            }
            }

            // Display SWF File
            function displaySwfFile(){
            if(swfLocation!=undefined){
            fadeIn(mediaSWF_mc, 1, this, "applyCursorStates");
            } else {
            trace("No SWF File Found, calling applyCursorStates");
            //applyCursorStates();
            }
            }

            function applyCursorStates(){
            // Apply MovieClip Methods to TextField
            vlaInstrOneTxt_mc.onRollOver = vlaInstrTwoTxt_mc.onRollOver =function(){
            cursorRollOverAudio();
            }

            vlaInstrOneTxt_mc.onRollOut = vlaInstrTwoTxt_mc.onRollOut =function(){
            cursorRollOutAudio();
            }

            vlaInstrOneTxt_mc.onRelease = function(){
            cursorRollOverAudio();
            playSFX(textOneAudio);
            }

            vlaInstrTwoTxt_mc.onRelease = function(){
            cursorRollOverAudio();
            playSFX(textTwoAudio);
            }
            }

            var __soundFX:Sound = new Sound();
            var audioFlag:Boolean = false;
            function playSFX(audioClip:String, targ:MovieClip, onComplete:String):Void {
            __soundFX.onLoad = function(success:Boolean){
            if(success){
            if(!audioFlag){
            audioFlag = true;
            __soundFX.start();
            trace("Audio Clip: "+audioClip+" is Now Playing");
            } else {
            __soundFX.stop();
            audioFlag = false;
            trace("Audio Clip Stopped");
            }
            }
            }
            var args = arguments.slice(3, arguments.length);
            __soundFX.onSoundComplete = function() {
            audioFlag = false;
            trace("Audio Clip Completed");
            if(onComplete!=undefined){
            trace("Audio "+audioClip+" Completed, Calling onComplete Method: "+onComplete);
            targ[onComplete](args);
            } else {
            trace("Audio Completed, no onComplete Method to Call");
            }
            };
            __soundFX.loadSound(audioClip,false);
            }

            // Stop Audio Method
            function stopSFX():Void {
            trace("__PLAYER: AUDIO CLIP STOPPED");
            __soundFX.stop();
            }

            loadSWF(swfLocation);
            • 3. Re: asfunction, cursor states, and moviclips...oh my
              kglad Adobe Community Professional & MVP
              there's no textOneContainer_mc in that code. copy and paste just the relevent parts of your code.
              • 4. Re: asfunction, cursor states, and moviclips...oh my
                flashWannaBe Level 1
                vlaInstrOneTxt_mc and vlaInstrTwoTxt_mc are the moviclips in which the textfields are contained in. The reason why there isn't textOneContainer_mc in this code is because I wanted to avoid having to post this all up and just give a relevant example.
                • 5. Re: asfunction, cursor states, and moviclips...oh my
                  flashWannaBe Level 1
                  The only other alternative I see at this point would be to put each word in its own separate movieclip. The reason being is because there may be a word within the sentence that contains a "glossary" word. That word, when clicked, need to luanch a glossary. However the other words, when clicked, will have an audio associated to it. At the same time, if I put each word in a separate movieclip, I lose the html font formatting. It's kind of a bum deal...a lot of work to put each word in a movieclip, position the movieclips so that it still looks like a sentence(s). I'm trying to find a work around on this, but no such luck.
                  • 6. Re: asfunction, cursor states, and moviclips...oh my
                    kglad Adobe Community Professional & MVP
                    that code will compile but nothing is accomplished by using MovieClip() as a function and TextField() as a function.

                    so, you're left with the problem and solutions i gave in my above message.