8 Replies Latest reply on Aug 20, 2009 2:38 PM by kglad

    OOP Load a Flash Page via External Action Script (.as File)

    Butchmu

      CS3 actionscript 2

      Is it possible. Can I make a flash file that is OOP and, also design a short movie clip within Flash without it being external actionscript?
      (Have done the above, but don't know if this is why I'm having a problem.)

      Now, for the real problem, how do I call that particular movie clip.

      I have worked on this for better than 2 weeks reading everything I can find, google, the forums, and their seems to be little information on OOP.

      Would someone post a very simple example of how to load a clip from the external actionscript.

      I know it is difficult for people to give up their time in the aide of others when they are lost and often are using incorrect terms. I will do my part, I will upload anything one may need to our server. I will provide all my code and share that code for you to use as desired. (some of it is really neat).

      I really do need some guidance,,,THANKS

      Here is my page that works inside the flash file.box
      and here is what I want it to do entire file will need to click question mark. It also hangs from a PC, but works most of the time from a Mac.

        • 1. Re: OOP Load a Flash Page via External Action Script (.as File)
          kglad Adobe Community Professional & MVP

          pass a movieclip to your constructor and use that to attach your linked library movieclip.  ie:

           

          // in your class file:

           

          .

          .

          public class C(mc:MovieClip){

          mc.attachMovie("yourlinkageID","mcName",depth);

           

           

          // in your fla:

           

           

          var c:C=new C(this);  // or pass any other movieclip

          1 person found this helpful
          • 2. Re: OOP Load a Flash Page via External Action Script (.as File)
            Butchmu Level 1

            I  really appreciate the reply.  Somewhere I'm missing something.  The compiler gave two errors

             

            1. error in script layer 1 line 1

            2. attribute used outside class

             

            I've tried everything I can think of.....I'm missing something, any suggestions,  I will try a hundred different ways all wrong to figure out one that is right.

             

            Again, thanks...it was  helpful, it was one more piece of information.

            • 3. Re: OOP Load a Flash Page via External Action Script (.as File)
              kglad Adobe Community Professional & MVP

              here's a complete class file that does what you want:

               

              class Main extends MovieClip{
                 
                  public function Main(tl:MovieClip){
                      tl.attachMovie("mcID","mc",1);  // mcID is a movieclips linkage id
                  }
                 
              }

               

               

              if you're still having problems, copy and paste your class file.

              1 person found this helpful
              • 4. Re: OOP Load a Flash Page via External Action Script (.as File)
                Butchmu Level 1

                I apologize for not getting this.  I have studied as many things as I can find.  I think somewhere on the web I've read some of your information.

                 

                Here is the class file:  I have made it in bold where I think the problem is:

                [CODE]dynamic class Screens.GeneralWizard extends Pseudo.PseudoBase {

                private var m_tab:MovieClip;

                private var m_tabData:MovieClip;

                private var m_tabBuild:MovieClip;

                private var m_btnMyGalleries:MovieClip;

                private var m_popupWnd:MovieClip;

                private var m_cardId:Object;

                private var m_cardTitle:String;

                private var m_bShared:Boolean;

                private var m_bOwn:Boolean;

                private var m_txtDblLabel:TextField;

                private var m_bSendOrder:Boolean;// flag true if after card saving order should be sent.

                private var m_bCardLog:Boolean;// flag true if after card saving the card log should open.

                private var m_bMyGalleries:Boolean;// flag true if after card saving we should go to My Galleries page.

                 

                public function GeneralWizard() {

                super();

                m_bSendOrder=false;

                m_bCardLog=false;

                m_bMyGalleries=false;

                m_cardId=0;

                m_bOwn=false;

                m_txtDblLabel=Screens.Settings.BaseSet.createLabel(this,1,"m_txtDblLabel");

                m_txtDblLabel.htmlText="<span class='bodySmall'>double click any object to edit.</span>";

                attachMovie("PseudoTab","m_tab",2);

                m_tab.setTabStyle("stdTop");

                m_tab.setCallback(this,onChangeTab);

                m_tab.addTab("<span class='button'>Layout</span>",Style.m_cssStyles);

                m_tabBuild=m_tab.setTabContent(0,"TabBuild");

                m_tabBuild.setOwner(this);

                m_tab.addTab("<span class='button'>Pick Image</span>",Style.m_cssStyles);

                m_tabData=m_tab.setTabContent(1,"TabData");

                m_tabData.setOwner(this);

                 

                attachMovie("PseudoPushButton","m_btnMyGalleries",5);

                m_btnMyGalleries.setHtmlText("<span class='button'>My Galleries</span>",Style.m_cssStyles);

                m_btnMyGalleries.setW(100);

                m_btnMyGalleries.setCallback(this,onMyGalleries);

                m_btnMyGalleries._visible=Style.m_bMyGalShow;

                }

                 

                //Help function by Butch

                public function onHelp():Void {           //"?" has been pressed help function

                //var obj=m_popupWnd.getValue();

                //m_popupWnd.lock();

                 

                // public class C(mc:MovieClip){

                mc.attachMovie("yourlinkageID","mcName",depth);


                //GlobalCs.help("","<span class='bodySmall'>                                                                                                                          </span>",Style.m_cssStyles,"",_global.cardRoot);

                }

                //end Help function by Butch

                 

                 

                private function onTest():Void {

                var xmlDoc:Object=toXML();

                xmlDoc.send(_global.phpPath + "printcard.php","_blank");

                }

                 

                private function onChangeTab(objTab:Object):Void {

                m_txtDblLabel.htmlText=objTab == 0?"<span class='bodySmall'>double click any object to edit.</span>":m_tabData.isChooseImage()?"<span class='bodySmall'>                                                                 </span>":"<span class='bodySmall'>Please choose an image to use as the background.</span>";

                m_txtDblLabel._x=m_tab.getW() - m_txtDblLabel._width;

                }

                 

                public function changeTab(objTab:Object):Void {

                m_tab.setActiveTab(objTab);

                }

                 

                public function getTabData():MovieClip {

                return m_tabData;

                }

                 

                public function update(loadingEnd:Boolean):Void {

                var btnH=m_btnMyGalleries._visible?m_btnMyGalleries.getH():0;

                m_tab.setSize(m_nW,m_nH - btnH - 5);

                m_tab.update();

                m_tabBuild.setSize(m_tab.getContentW(),m_tab.getContentH());

                m_tabBuild.update(loadingEnd);

                m_tabData.setSize(m_tab.getContentW(),m_tab.getContentH());

                m_tabData.update();

                m_btnMyGalleries.update();

                m_btnMyGalleries._y=m_tab._y + m_tab.getH() + 5;

                m_btnMyGalleries._x=m_tab._x;

                m_txtDblLabel._x=m_tab.getW() - m_txtDblLabel._width;

                setSize(m_tab.getW(),m_btnMyGalleries._y + m_btnMyGalleries.getH());

                }

                 

                public function drawWizard():Void {

                m_tab.drawTab();

                m_tabBuild.drawPane();

                m_tabBuild.drawSettings();

                m_tabData.drawGalleries();

                }

                 

                public function draw():Void {

                m_tab.draw();

                m_tabData.draw();

                m_tabBuild.draw();

                m_btnMyGalleries.draw();

                }

                 

                public function setTheme(strTheme:String):Void {

                super.setTheme(strTheme);

                m_tab.setTheme(strTheme);

                m_tabData.setTheme(strTheme);

                m_tabBuild.setTheme(strTheme);

                m_btnMyGalleries.setTheme(strTheme);

                }

                 

                public function setBgImage(data:Object):Void {

                m_tabBuild.setBgImage(data);

                }

                 

                public function chooseImage(element:Screens.Elements.ImageElement,bSwitch:Boolean):Void {

                if (bSwitch) {

                changeTab(1);

                }

                m_tabData.chooseImage(element);

                }

                 

                 

                private function onSaveBtn():Void {

                m_popupWnd=GlobalClass.createWindow(_global.cardRoot,"mcSaveWnd","Save card","modal",false,"SaveWnd",1006);

                var obj:Object=new Object  ;

                var strCardName:String=m_cardTitle;

                obj.strCardName=strCardName?strCardName:"";

                obj.bShared=m_bShared;

                m_popupWnd.setValue(obj);

                m_popupWnd.setCallback(this,onSave);

                m_popupWnd.setTheme(m_strTheme);

                m_popupWnd.update();

                m_popupWnd.draw();

                m_popupWnd._x=Math.round((Stage.width  - m_popupWnd.getW()) / 2);

                m_popupWnd._y=Math.round((Stage.height - m_popupWnd.getH()) / 2);

                }

                 

                public function onCardLog():Void {

                if (GlobalClass.m_bChanged) {

                var wnd:MovieClip=GlobalClass.alert("Warning","<span class='bodySmall'>Some changes to your layout have not been saved yet.<br>Would you like to save now?</span>",Style.m_cssStyles,"yes,YES,no,NO","iconWarning",_global.cardRoot);

                m_bCardLog=true;

                wnd.setCallback(wizard,Number(_global.cardId) && m_bOwn?wizard.onQuietSave:wizard.onLoudSave);

                } else {

                getURL(_global.phpPath + "cardlog.php","_top");

                }

                }

                 

                private function onMyGalleries():Void {

                if (GlobalClass.m_bChanged) {

                var wnd:MovieClip=GlobalClass.alert("Warning","<span class='bodySmall'>Some changes to your layout have not been saved yet.<br>Would you like to save now?</span>",Style.m_cssStyles,"yes,YES,no,NO","iconWarning",_global.cardRoot);

                m_bMyGalleries=true;

                wnd.setCallback(wizard,Number(_global.cardId) && m_bOwn?wizard.onQuietSave:wizard.onLoudSave);

                } else {

                getURL(_global.phpPath + "mygalleries.php?card_id=" + _global.cardId,"_top");

                m_bMyGalleries=false;

                }

                }

                 

                private function onOrder():Void {

                if (GlobalClass.m_bChanged) {

                var wnd:MovieClip=GlobalClass.alert("Warning","<span class='bodySmall'>Some changes to your layout have not been saved yet.<br>Would you like to save now?</span>",Style.m_cssStyles,"yes,YES,no,NO","iconWarning",_global.cardRoot);

                m_bSendOrder=true;

                wnd.setCallback(wizard,Number(_global.cardId) && m_bOwn?wizard.onQuietSave:wizard.onLoudSave);

                } else {

                m_bSendOrder=false;

                if (m_bOwn) {

                getURL(Style.m_strOrderURL + _global.cardId + "&v1=" + _global.ip + "&v2=" + _global.sid + "&" + Style.m_strOrderParams,Style.m_strOrderTarget);

                } else {

                GlobalClass.m_bChanged=true;

                onOrder();

                }

                }

                }

                 

                private function onLoudSave(strType:String):Void {

                if (strType == "yes") {

                onSaveBtn();

                } else {

                if (m_bSendOrder) {

                //check if we can order this card anyway

                if (Number(_global.cardId) && m_bOwn) {

                GlobalClass.m_bChanged=false;

                onOrder();

                } else {

                m_bSendOrder=false;

                }

                }

                if (m_bCardLog) {

                //Go to log anyway

                GlobalClass.m_bChanged=false;

                onCardLog();

                }

                if (m_bMyGalleries) {

                GlobalClass.m_bChanged=false;

                onMyGalleries();

                }

                 

                }

                }

                 

                private function onQuietSave(strType:String):Void {

                if (strType == "yes") {

                m_cardId=_global.cardId;

                saveCard();

                m_cardId=0;

                } else {

                if (m_bSendOrder) {

                //check if we can order this card anyway

                if (Number(_global.cardId) && m_bOwn) {

                GlobalClass.m_bChanged=false;

                onOrder();

                } else {

                m_bSendOrder=false;

                }

                }

                if (m_bCardLog) {

                //Go to log anyway

                GlobalClass.m_bChanged=false;

                onCardLog();

                }

                if (m_bMyGalleries) {

                GlobalClass.m_bChanged=false;

                onMyGalleries();

                }

                }

                }

                 

                private function onSave():Void {

                var obj=m_popupWnd.getValue();

                 

                m_popupWnd.lock();

                 

                if (! obj.strCardName) {

                GlobalClass.alert("Warning","<span class='bodySmall'>You should enter the name of the card.</span>",Style.m_cssStyles,"OK,OK","iconWarning",_global.cardRoot);

                } else {

                m_cardTitle=obj.strCardName;

                m_bShared=obj.bShared;

                var xmlDoc:Object=new XMLDocument  ;

                xmlDoc.m_pOwner=this;

                var xmlNode:XMLNode=xmlDoc.m_xmlNode.createElement("card");

                xmlNode.attributes.name=obj.strCardName;

                xmlDoc.m_xmlNode.appendChild(xmlNode);

                xmlDoc.m_xmlNode.contentType="text/xml";

                xmlDoc.m_xmlNode.onLoad=function(bSuccess:Boolean):Void

                {

                var xmlDoc:Object = this.m_pOwner;

                var wizard:MovieClip = xmlDoc.m_pOwner;

                var strId:String = "0";

                if(bSuccess)

                {

                wizard.m_cardId = xmlDoc.getNodeAttrib("card", "id");

                if(wizard.m_cardId == "0")

                wizard.saveCard();

                else

                {

                var strText:String = "<span class='bodySmall'>A card with this name already exists.<br>Overwrite?</span>";

                var wnd:MovieClip = GlobalClass.alert("Warning", strText, Style.m_cssStyles,

                "yes,Yes,no,No,cancel,Cancel", "iconWarning", _global.cardRoot);

                wnd.setCallback(wizard, wizard.onOverWrite);

                wizard.m_popupWnd.windowRollOut();

                }

                }

                };

                xmlDoc.m_xmlNode.sendAndLoad(_global.phpPath + "getcardid.php",xmlDoc.m_xmlNode);

                }

                }

                 

                private function saveCard():Void {

                var xmlCard:Object=new XMLDocument(Dynamic.DynXML(toXML()));

                var xmlRes:Object=new XMLDocument  ;

                xmlRes.m_pOwner=this;

                xmlRes.m_xmlNode.onLoad=function(bSuccess:Boolean):Void

                {

                var xmlDoc:Object = m_pOwner;

                var wizard:MovieClip = xmlDoc.m_pOwner;

                if(bSuccess)

                {

                GlobalClass.m_bChanged = false;

                var strText:String = "<span class='bodySmall'>" + xmlDoc.getNodeAttrib("saveCard", "text") + "</span>";

                var strIcon:String = xmlDoc.getNodeAttrib("saveCard", "icon");

                var wnd:MovieClip = GlobalClass.alert("Card", strText, Style.m_cssStyles,

                "ok,OK", strIcon, _global.cardRoot);

                wnd.setCallback(wizard.m_popupWnd, wizard.m_popupWnd.remove);

                _global.cardId = xmlDoc.getNodeAttrib("saveCard", "id");

                wizard.m_bOwn = true;

                if(wizard.m_bSendOrder) wizard.onOrder();

                if(wizard.m_bCardLog) wizard.onCardLog();

                if(wizard.m_bMyGalleries) wizard.onMyGalleries();

                }

                else

                {

                var strText:String = "<span class='bodySmall'>The card hasn't been saved.</span>";

                var wnd:MovieClip = GlobalClass.alert("Error", strText, Style.m_cssStyles,

                "ok,OK", "iconError", _global.cardRoot);

                wnd.setCallback(wizard.m_popupWnd, wizard.m_popupWnd.remove);

                }

                wizard.m_bSendOrder = false;

                wizard.m_bCardLog = false;

                wizard.m_bMyGalleries = false;

                wizard.m_popupWnd.windowRollOut();

                };

                xmlCard.m_xmlNode.sendAndLoad(_global.phpPath + "savecard.php",xmlRes.m_xmlNode);

                }

                 

                private function onOverWrite(strType:String):Void {

                switch (strType) {

                case "yes" :

                saveCard();

                m_cardId=0;

                break;

                case "no" :

                m_cardId=0;

                m_popupWnd.remove();

                break;

                }

                }

                 

                public function toXML(xmlDoc:XML):XMLNode {

                var m_cardXML:Object=new XMLDocument  ;

                var cardElement:XML=m_cardXML.m_xmlNode.createElement("card");

                cardElement.attributes.name=m_cardTitle;

                cardElement.attributes.shared=m_bShared?1:0;

                cardElement.attributes.id=m_cardId;

                m_cardXML.m_xmlNode.appendChild(cardElement);

                m_tabBuild.toXML(cardElement);

                m_cardXML.m_xmlNode.contentType="text/xml";

                return m_cardXML.m_xmlNode;

                }

                 

                public function fromXML(xmlNode:XMLNode):Void {

                var xmlCard:Object=xmlNode.childNodes[0];

                _global.arrFields.splice(1);

                for (var i=0; i < xmlCard.childNodes.length; i++) {

                if (xmlCard.childNodes[i].nodeName == "CardPage") {

                m_tabBuild.fromXML(xmlCard.childNodes[i]);

                }

                }

                }

                }[/CODE]

                 

                I am also attaching my flash source file the screen I'm trying to load is "CardAlert"

                 

                I would never ask for someone to do this for me without payment.  I am wanting to learn.  I can sent the complete source including all .as files if requested.  Your help is greatly appreciated and far beyond what is ever expected.

                • 5. Re: OOP Load a Flash Page via External Action Script (.as File)
                  kglad Adobe Community Professional & MVP

                  when you write code, you should do it stages:

                   

                  1.  create the basics of your class and then test.

                  2.  once that's debugged, add additional functionality and test.

                  3.  and continue repeating stage 2 until you achieve what you want.

                   

                  the code you pasted has problems unrelated to this thread.

                   

                  i suggest you start over using the advice i gave above.

                   

                  or if you want to hire me to fix your problems, set me an email via my website:  www.kglad.com

                  1 person found this helpful
                  • 6. Re: OOP Load a Flash Page via External Action Script (.as File)
                    Butchmu Level 1

                    A Special thanks for the time and effort provided.  The information provided in your post was very helpful, not always are we able to solve all problems. However the answers you provided are sure to help others.

                    • 8. Re: OOP Load a Flash Page via External Action Script (.as File)
                      kglad Adobe Community Professional & MVP

                      yes?

                       

                      i received an email in the past hour (2:30pm pst) from you.