A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: passing a variable to my MovieClip - should be simple!

  1. #1
    Junior Member
    Join Date
    Feb 2009
    Posts
    18

    passing a variable to my MovieClip - should be simple!

    Hello All,

    Thanks in advance for your help.

    I am trying to send a value from one of my xml nodes (<marker>) by declaring it in a function 'showData' as a variable 'XMLMarker'. If I trace this value (XMLmarker) it returns the right data found in the node <marker> (which is 'myMarker_mc'). However, I need to tell the stage that myMarker_mc is a MovieClip...please see the 'PROBLEM' stated in the code below.

    Code:
    stop();
    var placesXML:XML = 
    <places>
    	<place name= "Yogyakarta">
    		<frame>62</frame>
    		<Data>This is a delightful place in Java</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Banda_Aceh">
    		<frame>64</frame>
    		<Data>This is a delightful place in Northern Sumatra</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    
    	and so on....
    
    		<place name= "Gili_isles">
    		<frame>78</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    </places>
    
    var nameBtn:Array  = [Yogyakarta, Banda_Aceh, Bengkulu, Singapore_City, Dili, Jakarta, Taipei, Manila, Hanoi, Vientiane, Phnom_penh, Napyidaw, Bangkok, Kuala_lumpar, Bandar_seri_sagawan, solo, Gili_isles]; 
    var  i:int = nameBtn.length; 
    	while(i){        
    	i--;        
    	nameBtn[i].addEventListener(MouseEvent.CLICK, showData);
    }    
    
    //The above part all works well...
    
    function showData(e:MouseEvent):void{
    	
    	var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame; //works fine
    	var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; //This returns myMarker_mc - perfect!	
    	var XMLmarkers:String = xmlMarker.toString();//This also returns myMarker_mc, except now its a String - great!	
           var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data; //works fine
    	
    	
    	gotoAndStop(xmlFrame);//This works perfectly.
    	XMLmarkers.myText.htmlText = xmlData.toString();//PROBLEM - Now when the XMLmarkers variable is traced, it no longer shows 'myMarker_mc'. (What is shown is in the Code box further down this post)This line should activate the MovieClip (currently called 'myMarker_mc' on the stage). Within this movieclip there is a Dynamic textfield (called 'myText') and the text to go within this textfield comes from the variable (xmlData). 
    	
    	
    }
    You may ask, why do you want a variable to hold the value in the node <marker>, when that value is identical for each node, ie. it is always 'myMarker_mc', so why not just directly declare the variable 'xmlMark' as myMarker_mc. The reason is; the value in some of the <marker> nodes will soon be changing to 'myMarker_mc2' - a slightly different movieClip which I may need to call depending upon which place @name is chosen.

    This is the new output thrown up by the variable XMLmarkers

    Code:
    <marker>
      myMarker_mc
      <myText>
        <htmlText>&lt;p align="center"&gt;&lt;font size="4"&gt;&lt;font color="#CBB9AB"&gt;&lt;b&gt;INDONESIA&lt;/b&gt;&lt;font color="#000000"&gt; ……………. &lt;/p&gt;&lt;br&gt;&lt;br&gt;&lt;font color="#6259DF"&gt;&lt;p align="left"&gt;&lt;font size="2"&gt;&lt;b&gt;ABOUT&lt;/b&gt;&lt;br&gt;&lt;font color="#000000"&gt;……………………….......&lt;br&gt;&lt;br&gt;&lt;font color="#6259DF"&gt;&lt;b&gt;ATTRACTIONS&lt;/b&gt;&lt;br&gt;&lt;font color="#000000"&gt;Most travellers either spend their precious time elsewhere, or use this town for it’s transport connections.&lt;br&gt;&lt;br&gt;&lt;font color="#6259DF"&gt;&lt;b&gt;TRANSPORT&lt;/b&gt;&lt;br&gt;&lt;font color="#161672"&gt;&lt;i&gt;Air: &lt;/i&gt;&lt;font color="#000000"&gt;There is no airport here.&lt;br&gt;&lt;br&gt;&lt;font color="#161672"&gt;&lt;i&gt;Road: &lt;/i&gt;&lt;font color="#000000"&gt; where (Type, Duration, Cost), where (Type, Duration, Cost)&lt;br&gt;&lt;br&gt;&lt;font color="#161672"&gt;&lt;i&gt;Train: &lt;/i&gt;&lt;font color="#000000"&gt;There is no station here.&lt;br&gt;&lt;br&gt;&lt;font color="#4DFF00"&gt;&lt;b&gt;Sponsored Links&lt;/b&gt;&lt;br&gt;&lt;font color="#000000"&gt;&lt;a href="http://www.offsoon.com/advertise"&gt;&lt;u&gt;&lt;i&gt;Advertise&lt;/i&gt;&lt;/u&gt;&lt;/a&gt; with us&lt;br&gt;&lt;br&gt;&lt;font color="#6259DF"&gt;&lt;b&gt;Further Information&lt;/b&gt;&lt;br&gt;&lt;font color="#000000"&gt;&lt;a href="http://www.bbc.co.uk/weather/world/country_guides/results.shtml?tt=TT002320"&gt;Click &lt;u&gt;here&lt;/u&gt; to visit the BBC’s Weather page for Indonesia&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href="http://www.fco.gov.uk/en/travelling-and-living-overseas/travel-advice-by-country/asia-oceania/indonesia1"&gt;&lt;u&gt;FCO&lt;/u&gt; – Click for British Nationals travel requirements&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href="http://www.who.int/countries/idn/en/"&gt;&lt;u&gt;World Health Organisation&lt;/u&gt; – Click for news on Indonesia&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href="http://offsoon.com "&gt; &lt;u&gt; Off Soon.com Home Page…&lt;/u&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;font color="#FD2424"&gt;&lt;b&gt;Notes&lt;/b&gt;&lt;br&gt;&lt;font color="#000000"&gt;   Different areas present different risks, but travellers should remain vigilant within tourist-populated areas, as these have traditionally presented themselves as targets to Terrorist Groups.&lt;br&gt;&lt;br&gt;   Petty Crime such as pick-pocketing, or theft does exist and tourists remain particularly vulnerable upon public transport, whilst walking backstreets alone, and especially if high value items are displayed.&lt;br&gt;&lt;br&gt;   Travellers should also be aware of localised political situations as violence has occasionally followed rallies and demonstrations.&lt;br&gt;&lt;br&gt;   Travellers should also be aware of Muslim practices and be careful not to cause offence whilst visiting different parts of Indonesia – this is particularly prevalent during the month of Ramadan. &lt;br&gt;&lt;br&gt;   If you plan on Driving in Indonesia, please obtain a valid international Driving Licence. &lt;br&gt;&lt;br&gt;   Due to Indonesia’s geographical position, the area is particularly susceptible to flash flooding, earthquakes and volcanic activity – this often results in impassable transport routes.  &lt;br&gt;&lt;br&gt;&lt;font color="#6259DF"&gt;&lt;a ef="http//:offsoon.com/disclaimer"&gt;&lt;u&gt;&lt;b&gt;Disclaimer&lt;/b&gt;&lt;/u&gt;&lt;/a&gt;&lt;/p&gt;</htmlText>
      </myText>
    </marker>
    Bizarre...

    Please help!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    First, I don't think that the code you posted is the code you actually have. The posted code should throw an error about no such property "myText" on object with static type String. You probably put xmlMarker (which is an XMLList) rather than XMLMarkers (which is a String).

    But even if you were referring to the String like you thought you were, a String is not a MovieClip. You can use getChildByName to get a displayObject by instancename.

  3. #3
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Thanks for your reply 5TonsofFlax,

    I have now imported:import flash.display.MovieClip; at the top of the script and inserted...

    Code:
    function showData(e:MouseEvent):void{
    	
    var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame;
    var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; 	
    //var XMLmarkers:String = xmlMarker.toString();//This returns 'myMarker_mc'
    var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data;
    var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker;
    gotoAndStop(xmlFrame);
    	
    MovieClip(getChildByName(xmlMarker)).myText.htmlText = xmlData.toString();
    	
    
    	
    	//trace ("-----------------");
    	trace (xmlMarker);
    	
    }
    ...into the showData function and it works beautifully, EXCEPT when I alter one of the <marker> nodes to 'mc_myMarker2' - which refers to an instance of a movieclip on stage, just like 'myMarker_mc'.

    A snippet from my New XML

    Code:
    <place name= "Dili">
    		<frame>66</frame>
    		<Data>This is a delightful place in East Timor</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Jakarta">
    		<frame>67</frame>
    		<Data>This is a delightful place in Java</Data>
    		<marker>mc_myMarker2</marker>//this will be the changed marker to mc_myMarker2 -  the changed marker - it matches the instance on stage within Jakarta in frame 67.
    	</place>
    	<place name= "Taipei">
    		<frame>68</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Manila">
    		<frame>69</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    So those places with a <marker> node value of 'myMarker_mc' works perfectly, but Jakarata with a <marker>node value of 'mc_myMarker2'. The latter just throws up:

    Code:
    Error #1009: Cannot access a property or method of a null object reference.
    Any ideas?

    Many Thanks, it's warmly appreciated!

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Stupid question, but are you absolutely sure that the names match? I ask because it seems weird to switch from myMarker_mc to mc_MyMarker2 rather than myMarker_mc2.

    If the names really do match, then be sure that the named clip is actually on the frame in which that code executes.

  5. #5
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Thanks for your efforts 5Tons of Flax,

    I have treble checked my .fla - it works perfectly, if I stick to the node 'myMarker_mc', but as soon as I change that <marker> name - it won't have any of it. Just keeps throwing up:

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at MapMovieClipJune09TrialMarkersB_fla::MainTimeline/showData()[MapMovieClipJune09TrialMarkersB_fla.MainTimeline::frame61:120] //This appears in the 'Output Display', not as a compiler error.
    If I trace (XMLmarkers); the code appears fine, the content of the node is succesfully 'outputted' - either 'myMarker_mc', or 'myMarker_mcOne'. However, line 120 - as indicated in the error above - is obviously causing the problem.

    Code:
    MovieClip(getChildByName(XMLmarkers)).myText.htmlText = xmlData.toString();
    The MovieClips myMarker_mc and myMarker_mcOne are identical. On the relevant frame, either one of these are present - they both have 'instance of...' and 'instance name' the same. I just don't see the problem??!?

    Full code below: You can ignore the first bulk, as it's all XML. Although I have highlighted the offensive <marker> node.

    Code:
    stop();
    import flash.display.MovieClip;
    
    var placesXML:XML = 
    <places>
    	<place name= "Yogyakarta">
    		<frame>62</frame>
    		<Data>This is a delightful place in Java</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Banda_Aceh">
    		<frame>64</frame>
    		<Data>This is a delightful place in Northern Sumatra</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Bengkulu">
    		<frame>63</frame>
    		<Data><![CDATA[<p align="center"><font size="4"><font color="#CBB9AB"><b>INDONESIA</b><font color="#000000"> ……………. </p><br><br><font color="#6259DF"><p align="left"><font size="2"><b>ABOUT</b><br><font color="#000000">……………………….......<br><br><font color="#6259DF"><b>ATTRACTIONS</b><br><font color="#000000">Most travellers either spend their precious time elsewhere, or use this town for it’s transport connections.<br><br><font color="#6259DF"><b>TRANSPORT</b><br><font color="#161672"><i>Air: </i><font color="#000000">There is no airport here.<br><br><font color="#161672"><i>Road: </i><font color="#000000"> where (Type, Duration, Cost), where (Type, Duration, Cost)<br><br><font color="#161672"><i>Train: </i><font color="#000000">There is no station here.<br><br><font color="#4DFF00"><b>Sponsored Links</b><br><font color="#000000"><a href="http://www.offsoon.com/advertise"><u><i>Advertise</i></u></a> with us<br><br><font color="#6259DF"><b>Further Information</b><br><font color="#000000"><a href="http://www.bbc.co.uk/weather/world/country_guides/results.shtml?tt=TT002320">Click <u>here</u> to visit the BBC’s Weather page for Indonesia</a><br><br><a href="http://www.fco.gov.uk/en/travelling-and-living-overseas/travel-advice-by-country/asia-oceania/indonesia1"><u>FCO</u> – Click for British Nationals travel requirements</a><br><br><a href="http://www.who.int/countries/idn/en/"><u>World Health Organisation</u> – Click for news on Indonesia</a><br><br><a href="http://offsoon.com "> <u> Off Soon.com Home Page…</u></a><br><br><font color="#FD2424"><b>Notes</b><br><font color="#000000">   Different areas present different risks, but travellers should remain vigilant within tourist-populated areas, as these have traditionally presented themselves as targets to Terrorist Groups.<br><br>   Petty Crime such as pick-pocketing, or theft does exist and tourists remain particularly vulnerable upon public transport, whilst walking backstreets alone, and especially if high value items are displayed.<br><br>   Travellers should also be aware of localised political situations as violence has occasionally followed rallies and demonstrations.<br><br>   Travellers should also be aware of Muslim practices and be careful not to cause offence whilst visiting different parts of Indonesia – this is particularly prevalent during the month of Ramadan. <br><br>   If you plan on Driving in Indonesia, please obtain a valid international Driving Licence. <br><br>   Due to Indonesia’s geographical position, the area is particularly susceptible to flash flooding, earthquakes and volcanic activity – this often results in impassable transport routes.  <br><br><font color="#6259DF"><a ef="http//:offsoon.com/disclaimer"><u><b>Disclaimer</b></u></a></p>]]></Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Singapore_City">
    		<frame>65</frame>
    		<Data>This is a delightful place in East Timor</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Dili">
    		<frame>66</frame>
    		<Data>This is a delightful place in East Timor</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Jakarta">
    		<frame>67</frame>
    		<Data>This is a delightful place in Java</Data>
    		<marker>myMarker_mcOne</marker>
    	</place>
    	<place name= "Taipei">
    		<frame>68</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Manila">
    		<frame>69</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Hanoi">
    		<frame>70</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Vientiane">
    		<frame>71</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Phnom_penh">
    		<frame>72</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Napyidaw">
    		<frame>73</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Bangkok">
    		<frame>74</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Kuala_lumpar">
    		<frame>75</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Bandar_seri_sagawan">
    		<frame>76</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "solo">
    		<frame>77</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Gili_isles">
    		<frame>78</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    </places>
    
    //trace(placesXML.place.(@name=="solo").marker);
    //var xmlMarkers:MovieClip = myMarker_mc; //If movieclip is followed by = myMarker_mc - it all works (without the line in the showData function) - Iwant to transfer the xml data from <marker> into the MovieClip
    
    var nameBtn:Array  = [Yogyakarta, Banda_Aceh, Bengkulu, Singapore_City, Dili, Jakarta, Taipei, Manila, Hanoi, Vientiane, Phnom_penh, Napyidaw, Bangkok, Kuala_lumpar, Bandar_seri_sagawan, solo, Gili_isles]; 
    var  i:int = nameBtn.length; 
    	while(i){        
    	i--;        
    	nameBtn[i].addEventListener(MouseEvent.CLICK, showData);
    }    
    
    trace(placesXML.child.(@name =="solo").marker);
    
    
    
    function showData(e:MouseEvent):void{
    	
    	var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame;
    	var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; 	
    	var XMLmarkers:String = xmlMarker.toString();
    	var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data;
    	
    	gotoAndStop(xmlFrame);
    	MovieClip(getChildByName(XMLmarkers)).myText.htmlText = xmlData.toString();
    	//trace(XMLmarkers);
    	//trace(xmlData);
    	//trace ("-----------------");
    	trace (XMLmarkers);
    	
    }
    
    
    
    /* - From here onwards...
    function removeMarker(event:MouseEvent):void 
    {
    	gotoAndStop(61);
    }
    
    MovieClip(getChildByName(XMLmarkers)).bt_remove.addEventListener(MouseEvent.CLICK, removeMarker);
    
    
    function scrollUp (Event:MouseEvent):void {
    	
    	MovieClip(getChildByName(XMLmarkers)).myText.scrollV -= 1;
    	
    }
    
    function scrollDown (Event:MouseEvent):void {
    	
    	MovieClip(getChildByName(XMLmarkers)).myText.scrollV += 1;
    }
    
    
    MovieClip(getChildByName(XMLmarkers)).bt_up.addEventListener (MouseEvent.CLICK, scrollUp)
    
    MovieClip(getChildByName(XMLmarkers)).bt_dn.addEventListener (MouseEvent.CLICK, scrollDown)
    */
    I also wanted to carry on the value of the variable for use below the indicator
    'from here onwards' - However even whilst using the functioning movieClip 'myMarker_mc', the rest of the code doesn't want to know. Do I have to declare the value of the variable outside of the function 'showData' for the rest to work?

    FYI: 'myText','bt_dn','bt_up' and 'bt_remove' (buttons) are all nested within the movieClips; myMarker_mc and myMarker_mcOne.

    Could this error be chucked out by anything else?

    As ever, your time is appreciated!

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    First, as I tried to say above, I think the problem is that your specified clip is not on the frame in which the code executes. This part:
    Code:
    	gotoAndStop(xmlFrame);
    	MovieClip(getChildByName(XMLmarkers)).myText.htmlText = xmlData.toString();
    makes me think you expect the second line to execute in the context of the frame specified by xmlFrame. It won't. The entire function will complete before the frame switches.

    Second, yes, any variable declared within a function is scoped to that function and will not be available outside it. If you want to use XMLmarkers in the other code it has to be declared in a scope which includes those, such as the frame or the class.

  7. #7
    Junior Member
    Join Date
    Feb 2009
    Posts
    18

    MoveClip's children not recognised?

    Hi 5TonsOfFlax

    After considering what you said and messing about with custom classes, I can now get my movieclip to be presented on the correct frame. However, the children within it (bt_up, bt_dn and bt_remove (all buttons) and myText (a textfield)) are only recognised in the one of the 2 movieclips.

    Just to refresh your memory, I have 2 movieclips on stage; one called 'myMarker_mc', the other called 'myMarker_mcOne') - they both contain 4 children (bt_up, bt_dn, bt_remove ) and myText (a textfield) and they only work properly when it is the 'myMarker_mc' that is being called (called from the xml at the top of the file).

    Code:
    stop();
    import flash.display.MovieClip;
    import flash.text.TextField;
    
    var placesXML:XML = 
    <places>
    	<place name= "Yogyakarta">
    		<frame>62</frame>
    		<Data>This is a delightful place in Java</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Banda_Aceh">
    		<frame>64</frame>
    		<Data>This is a delightful place in Northern Sumatra</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Bengkulu">
    		<frame>63</frame>
    		<Data><![CDATA[<p align="center"><font size="4"><font color="#CBB9AB"><b>INDONESIA</b><font color="#000000"> ……………. </p><br><br><font color="#6259DF"><p align="left"><font size="2"><b>ABOUT</b><br><font color="#000000">……………………….......<br><br><font color="#6259DF"><b>ATTRACTIONS</b><br><font color="#000000">Most travellers either spend their precious time elsewhere, or use this town for it’s transport connections.<br><br><font color="#6259DF"><b>TRANSPORT</b><br><font color="#161672"><i>Air: </i><font color="#000000">There is no airport here.<br><br><font color="#161672"><i>Road: </i><font color="#000000"> where (Type, Duration, Cost), where (Type, Duration, Cost)<br><br><font color="#161672"><i>Train: </i><font color="#000000">There is no station here.<br><br><font color="#4DFF00"><b>Sponsored Links</b><br><font color="#000000"><a href="http://www.offsoon.com/advertise"><u><i>Advertise</i></u></a> with us<br><br><font color="#6259DF"><b>Further Information</b><br><font color="#000000"><a href="http://www.bbc.co.uk/weather/world/country_guides/results.shtml?tt=TT002320">Click <u>here</u> to visit the BBC’s Weather page for Indonesia</a><br><br><a href="http://www.fco.gov.uk/en/travelling-and-living-overseas/travel-advice-by-country/asia-oceania/indonesia1"><u>FCO</u> – Click for British Nationals travel requirements</a><br><br><a href="http://www.who.int/countries/idn/en/"><u>World Health Organisation</u> – Click for news on Indonesia</a><br><br><a href="http://offsoon.com "> <u> Off Soon.com Home Page…</u></a><br><br><font color="#FD2424"><b>Notes</b><br><font color="#000000">   Different areas present different risks, but travellers should remain vigilant within tourist-populated areas, as these have traditionally presented themselves as targets to Terrorist Groups.<br><br>   Petty Crime such as pick-pocketing, or theft does exist and tourists remain particularly vulnerable upon public transport, whilst walking backstreets alone, and especially if high value items are displayed.<br><br>   Travellers should also be aware of localised political situations as violence has occasionally followed rallies and demonstrations.<br><br>   Travellers should also be aware of Muslim practices and be careful not to cause offence whilst visiting different parts of Indonesia – this is particularly prevalent during the month of Ramadan. <br><br>   If you plan on Driving in Indonesia, please obtain a valid international Driving Licence. <br><br>   Due to Indonesia’s geographical position, the area is particularly susceptible to flash flooding, earthquakes and volcanic activity – this often results in impassable transport routes.  <br><br><font color="#6259DF"><a ef="http//:offsoon.com/disclaimer"><u><b>Disclaimer</b></u></a></p>]]></Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Singapore_City">
    		<frame>65</frame>
    		<Data>This is a delightful place in East Timor</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Dili">
    		<frame>66</frame>
    		<Data>This is a delightful place in East Timor</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Jakarta">
    		<frame>67</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mcOne</marker>
    	</place>
    	<place name= "Taipei">
    		<frame>68</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Manila">
    		<frame>69</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Hanoi">
    		<frame>70</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Vientiane">
    		<frame>71</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Phnom_penh">
    		<frame>72</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Napyidaw">
    		<frame>73</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Bangkok">
    		<frame>74</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Kuala_lumpar">
    		<frame>75</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Bandar_seri_sagawan">
    		<frame>76</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "solo">
    		<frame>77</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    	<place name= "Gili_isles">
    		<frame>78</frame>
    		<Data>This is a delightful place in Singapore</Data>
    		<marker>myMarker_mc</marker>
    	</place>
    </places>
    
    //trace(placesXML.place.(@name=="solo").marker);
    //var xmlMarkers:MovieClip = myMarker_mc; //If movieclip is followed by = myMarker_mc - it all works (without the line in the showData function) - Iwant to transfer the xml data from <marker> into the MovieClip
    
    var nameBtn:Array  = [Yogyakarta, Banda_Aceh, Bengkulu, Singapore_City, Dili, Jakarta, Taipei, Manila, Hanoi, Vientiane, Phnom_penh, Napyidaw, Bangkok, Kuala_lumpar, Bandar_seri_sagawan, solo, Gili_isles]; 
    var  i:int = nameBtn.length; 
    	while(i){        
    	i--;        
    	nameBtn[i].addEventListener(MouseEvent.CLICK, showData);
    }    
    //This part above works perfectly.
    
    function showData(e:MouseEvent):void{
    	
    	var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame;
    	var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; 	
    	var XMLmarkers:String = xmlMarker.toString();
    	var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data;
    	MovieClip(getChildByName(XMLmarkers)).myText.htmlText = xmlData.toString(); //PROBLEM - 'myText' works when the 'myMarker_mc' MovieClip is called - displays 'xmlData' perfectly. But when 'myMarker_mcOne' is called - nothing is produced within myText and the output box pops up...:mad:
    	
    	
    	gotoAndStop(xmlFrame); //works correctly
    	trace(XMLmarkers);//traces correct correctly. ie when user clicks on the 'Jakarta' button on stage, output is 'myMarker_mcOne', in all other cases it outputs; 'myMarker_mc'.
    
    //but then these buttons only work when myMarker_mc is called	MovieClip(getChildByName(XMLmarkers)).bt_remove.addEventListener(MouseEvent.CLICK, removeMarker);
    	MovieClip(getChildByName(XMLmarkers)).bt_up.addEventListener(MouseEvent.CLICK, scrollUp);
    	MovieClip(getChildByName(XMLmarkers)).bt_dn.addEventListener(MouseEvent.CLICK, scrollDown);
    	
    	function removeMarker (e:MouseEvent):void{
    		gotoAndStop(61);
    	}
    	
    	function scrollUp (e:MouseEvent):void{
    		MovieClip(getChildByName(XMLmarkers)).myText.scrollV -= 1;
    	}
    	
    	function scrollDown (e:MouseEvent):void{
    		MovieClip(getChildByName(XMLmarkers)).myText.scrollV += 1;
    	}
    	
    }
    When myMarker_mcOne is called the dynamic textfield, called 'myText' produces a blank and the output box pops up with...

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at MapMovieClipJune09TrialMarkersB_fla::MainTimeline/showData()[MapMovieClipJune09TrialMarkersB_fla.MainTimeline::frame61:126]
    I don't understand how the one movieclip works and the other isn't recognised, when it is there before my own eyes and the name of it is traced correctly !! This now officially driving me nuts!

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You need to determine what on that line is actually null. Trace out each of the parts in order.
    Code:
    trace("clip:", getChildByName(XMLMarkers));
    trace("bt_remove:", MovieClip(getChildByName(XMLMarkers)).bt_remove);

  9. #9
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Thanks for your reply 5TonsOfFlax,

    When I use those traces in the function 'showData', they both return compiler errors;

    Code:
    1120: Access of undefined property XMLMarkers.
    ..shown in code excerpt below...

    Code:
    function showData(e:MouseEvent):void{
    	
    	var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame;
    	var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; 	
    	var XMLmarkers:String = xmlMarker.toString();
    	var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data;
    	MovieClip(getChildByName(XMLmarkers)).myText.htmlText = xmlData.toString();
    	
    	
    	
    	gotoAndStop(xmlFrame);
    	trace(XMLmarkers);However, this does trace the correct XML text dependent upon which button is clicked.
    	
    	
    	
    	MovieClip(getChildByName(XMLmarkers)).bt_remove.addEventListener(MouseEvent.CLICK, removeMarker);
    	MovieClip(getChildByName(XMLmarkers)).bt_up.addEventListener(MouseEvent.CLICK, scrollUp);
    	MovieClip(getChildByName(XMLmarkers)).bt_dn.addEventListener(MouseEvent.CLICK, scrollDown);
    	
    	function removeMarker (e:MouseEvent):void{
    		gotoAndStop(61);
    	}
    	
    	function scrollUp (e:MouseEvent):void{
    		MovieClip(getChildByName(XMLmarkers)).myText.scrollV -= 1;
    	}
    	
    	function scrollDown (e:MouseEvent):void{
    		MovieClip(getChildByName(XMLmarkers)).myText.scrollV += 1;
    	}
    	
    	
    	trace("clip:", getChildByName(XMLMarkers));//returns error 1120
    	trace("bt_remove:", MovieClip (getChildByName(XMLMarkers)).bt_remove);//returns error 1120
    	
    }
    So the script is able to return the correct XML element text, but can only connect it to one of the placed movieclips on the stage..

    Why is the value of the xml node not being correctly linked to both types of movieclip on stage?

    As ever, cheers

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    In this case, I think it's simply that I capitalized the "m" in XMLMarkers and your code has it lowercase. My mistake.

  11. #11
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Cheers, my mind was obviously frazzled, I should have spotted that.

    I firstly inserted;

    Code:
    function showData(e:MouseEvent):void{
    	
    	var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame;
    	var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; 	
    	var XMLmarkers:String = xmlMarker.toString();
    	var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data;
    	MovieClip(getChildByName(XMLmarkers)).myText.htmlText = xmlData.toString();
    	
    	
    	
    	gotoAndStop(xmlFrame);
    	trace(XMLmarkers);	
    	
    	MovieClip(getChildByName(XMLmarkers)).bt_remove.addEventListener(MouseEvent.CLICK, removeMarker);
    	MovieClip(getChildByName(XMLmarkers)).bt_up.addEventListener(MouseEvent.CLICK, scrollUp);
    	MovieClip(getChildByName(XMLmarkers)).bt_dn.addEventListener(MouseEvent.CLICK, scrollDown);
    	
    	function removeMarker (e:MouseEvent):void{
    		gotoAndStop(61);
    	}
    	
    	function scrollUp (e:MouseEvent):void{
    		MovieClip(getChildByName(XMLmarkers)).myText.scrollV -= 1;
    	}
    	
    	function scrollDown (e:MouseEvent):void{
    		MovieClip(getChildByName(XMLmarkers)).myText.scrollV += 1;
    	}
    	
    	
    	trace("clip:", MovieClip (getChildByName(XMLmarkers)));
    	//trace("bt_remove:", MovieClip(getChildByName(XMLmarkers)).bt_remove);
    }
    Anyway, playing the movie reveals that;

    1.clicking on a button with a <marker> node of 'myMarker_mc' - output states;
    Code:
    clip: [object myMarker_mc_6]
    and all works fine.

    2. Clicking on a button ('Jakarta' in this case) with a <marker> node of 'myMarker_mcOne' states;
    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at MapMovieClipJune09TrialMarkersB_fla::MainTimeline/showData()[MapMovieClipJune09TrialMarkersB_fla.MainTimeline::frame61:128]
    line 128 contains...

    Code:
    MovieClip(getChildByName(XMLmarkers)).bt_remove.addEventListener(MouseEvent.CLICK, removeMarker);
    ie the first of my 'child buttons' (bt_remove).

    If i comment out line 128 and the relative function, the output still states...

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at MapMovieClipJune09TrialMarkersB_fla::MainTimeline/showData()[MapMovieClipJune09TrialMarkersB_fla.MainTimeline::frame61:129]
    Line 129 refers to the next button in sequence...

    I think that this must suggest that the script is not recognising the parent movieclip 'myMarker_mcOne' - despite the xml reference being traced correctly. I am just none the wiser as to how this can be, particlularly as the other movieclip on the stage.

    How can I make the script/stage. or whatever realise that myMarker_mcOne is a valid MovieClip??

    Cheers

  12. #12
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The point of the traces I suggested was to determine whether it was the clip or the buttons on the clip which were directly causing the null error.

    I suspect it is the clip, and I further suspect that it's because that clip is not on that frame, which means that myMarker_mcOne is NOT a valid MovieClip in the context that code is running in.

  13. #13
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    I dont understand how it isnt valid, I created myMarker_mcOne from myMarker_mc - both are library items, with their relevant instances on stage. All named correctly and matching the xml code.

    What could I have done in the copying of a movieclip in altering it's functionality.

    Just tried to upload the .fla but too large..

  14. #14
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    What frame is myMarker_mc on? Is myMarker_mcOne on the same frame? If not, that's your problem.
    If it is on the same frame, then there's something about your project I don't understand yet.

    You can use rapidshare or megaupload or one of those kind of services to put your fla up. I won't be able to get to it until late tonight, and only if you save for cs3. But maybe someone else can take a look.

  15. #15
    Junior Member
    Join Date
    Feb 2009
    Posts
    18
    Hi 5TonsOfFlax,

    There's no time limit - I just appreciate your help immensely - it's been doing my nut in!

    Link: http://rapidshare.com/files/26376474...kersUpload.fla

  16. #16
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The problem is that it takes some time (about 1 frame) to set up after switching frames. So if you try to immediately access clips through the displayList, they aren't actually on it yet and you get null. To fix it, I made a function generating function which makes a self-removing enter frame listener. The listener checks for the existence of the clip, and once it finds it sets up the other functionality after removing itself.
    I also moved the named functions that were defined inside showData out to clarify the scope.

    Here's the relevant code:
    Code:
    function showData(e:MouseEvent):void{
    	
    	var xmlFrame:int = placesXML.*.(@name == e.currentTarget.name).frame;
    	var xmlMarker:XMLList = placesXML.*.(@name == e.currentTarget.name).marker; 	
    	var XMLmarkers:String = xmlMarker.toString();
    	var xmlData:XMLList = placesXML.*.(@name == e.currentTarget.name).Data;
     	gotoAndStop(xmlFrame);
    	addEventListener(Event.ENTER_FRAME, frameListener(XMLmarkers, xmlData.toString()));
    }
    
    function frameListener(clipName:String, descText:String):Function{
    	return function(e:Event):void{
    		var clip:MovieClip = MovieClip(getChildByName(clipName));
    		if (clip != null){
    			e.currentTarget.removeEventListener(Event.ENTER_FRAME, arguments.callee);
    			clip.myText.htmlText = descText;
    			clip.bt_remove.addEventListener(MouseEvent.CLICK, removeMarker);
    			clip.bt_up.addEventListener(MouseEvent.CLICK, scrollUp);
    			clip.bt_dn.addEventListener(MouseEvent.CLICK, scrollDown);
    		}
    	}
    }
    
    function removeMarker (e:MouseEvent):void{
    	gotoAndStop(61);
    }
    
    function scrollUp (e:MouseEvent):void{
    	MovieClip(e.currentTarget.parent).myText.scrollV -= 1;
    }
    
    function scrollDown (e:MouseEvent):void{
    	MovieClip(e.currentTarget.parent).myText.scrollV += 1;
    }
    http://rapidshare.com/files/26385871...pload.fla.html

  17. #17
    Junior Member
    Join Date
    Feb 2009
    Posts
    18

    resolved

    What can I say - your a genius. This was way beyond my skill set, thanks for your efforts I have learnt a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center