Search Options
close
Search the following clips:
All Clips
Everyone's Clips
My Guides
Sign Up
Install
Learn More
Login
[AS3]実行時に未定義のプロパティにアクセスする方法
schneemoca
follow
0
6-23-2009 5:11 AM
455 views
Add a Comment
Login
to Comment. Not a member yet?
Sign up
Today's Top Clips
Kansas: Man Somehow Lifts Car Off 6-Year-Old Girl
Meet Japan's First Western Geisha
The "patron saint of Troublemakers" :)
How to tell when someone"s Lying
Have you ever wondered what hope looks like? Meet Celeste Fleck
Mega Shrooms!
The bottom line on global warming
Christian teacher sacked as she is told that sharing her faith is 'bullying'
Sara Smile
The Entire Known Universe in 6 minutes
visit the
Top Clips page
View the Top Clips from
June 23, 2009
Embed This Clip In Your Site...
<div style="margin: 12px 0px; font-family: arial; color: #333333; background: #ffffff; border: solid 4px #e5e5e5; width: 100%; clear: left;"><div class="CM_CTB_Content_Wrap" style="margin: 0px; padding: 0px;background-color: #ffffff;"><div style="border-bottom: solid 1px #dcdcdc; white-space: nowrap; margin-bottom: 8px; background-color: #eeeeee ;background-image: url(http://clipmarks.com/images/source-bg.gif); background-repeat: repeat-x; height: 24px; line-height: 24px; vertical-align: middle; padding-bottom: 4px; color: #666666; font-size: 10px;" ><a href="http://clipmarks.com/clip-to-blog/" title="see clips that are hot right now"><img src="http://content.clipmarks.com/blog_embed/3d6d9e26-5780-4082-a1ec-52d56ec6b73c/879D77BB-AB43-4BA1-9351-526CE699CD4E/" alt="" width="19" height="19" border="0" style="vertical-align: middle; margin: 0px 4px; display: inline; border: none; float:none;" /></a>clipped from <a title="http://source-laboratory.net/blog/flash/" href="http://source-laboratory.net/blog/flash/" style="font-size: 11px;">source-laboratory.net</a></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><H2><A href="http://source-laboratory.net/blog/2009/05/as3.html">[AS3]実行時に未定義のプロパティにアクセスする方法</A></H2></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><P>例えばライブラリから読み込んだSpriteの子Spriteにインスタンス名でアクセスしたいとか。これを普通にライブラリから読み込んだSpriteの子にアクセスしようとして、</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><DIV class="dp-highlighter nogutter"><DIV class="bar"><DIV class="tools"><A href="#">view plain</A><A href="#">copy to clipboard</A><A href="#">print</A><A href="#">?</A></DIV></DIV><OL start="1" class="dp-as"><LI class="alt"><SPAN><SPAN class="comment">//ライブラリからアタッチ</SPAN><SPAN> </SPAN></SPAN></LI><LI class=""><SPAN><SPAN class="variable">var</SPAN><SPAN> sp:Sprite = </SPAN><SPAN class="keyword">new</SPAN><SPAN> spriteAttachedFromLibrary() </SPAN><SPAN class="keyword">as</SPAN><SPAN> Sprite; </SPAN></SPAN></LI><LI class="alt"><SPAN><SPAN class="comment">//子Spriteにアクセス</SPAN><SPAN> </SPAN></SPAN></LI><LI class=""><SPAN><SPAN class="variable">var</SPAN><SPAN> spChild:Sprite = sp.spriteAttachedFromLibraryChild; </SPAN></SPAN></LI></OL></DIV></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><P>とすると、 「<I>1119: 未定義である可能性が高いプロパティ "インスタンス名" に静的型 flash.display:Sprite の参照を使用してアクセスしています。</I>」 と怒られる。</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><P>これを回避するためには[]演算子でストリングリテラルを使ってアクセスする。 上記の場合だと、</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><DIV class="dp-highlighter nogutter"><DIV class="bar"><DIV class="tools"><A href="#">view plain</A><A href="#">copy to clipboard</A><A href="#">print</A><A href="#">?</A></DIV></DIV><OL start="1" class="dp-as"><LI class="alt"><SPAN><SPAN class="comment">//ライブラリからアタッチ</SPAN><SPAN> </SPAN></SPAN></LI><LI class=""><SPAN><SPAN class="variable">var</SPAN><SPAN> sp:Sprite = </SPAN><SPAN class="keyword">new</SPAN><SPAN> spriteAttachedFromLibrary() </SPAN><SPAN class="keyword">as</SPAN><SPAN> Sprite; </SPAN></SPAN></LI><LI class="alt"><SPAN><SPAN class="comment">//[]演算子で子Spriteにアクセス</SPAN><SPAN> </SPAN></SPAN></LI><LI class=""><SPAN><SPAN class="variable">var</SPAN><SPAN> spChild:Sprite = sp[ </SPAN><SPAN class="string">"spriteAttachedFromLibraryChild"</SPAN><SPAN> ]; </SPAN></SPAN></LI></OL></DIV></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><P>こうするとエラー回避してアクセスできる。(via 凹村さん、ありがとうございました。)</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://source-laboratory.net/blog/flash/"><DIV id="code">#追記(09.05.01) 凹村さんに再度コメントいただきました。こういう時は<A href="http://livedocs.adobe.com/flex/2_jp/langref/flash/display/DisplayObjectContainer.html#getChildByName%28%29">getChildByName</A>を使って子Spriteの参照引っ張ってくる方が妥当みたい。もしくはdynamicクラスのMovieClipを継承させて、そのままドットシンタックスでアクセスするか。</DIV></blockquote></div><div style="margin: 0px 6px 6px 4px;"><table style="font-size: 11px;border-spacing: 0px;padding: 0px;" cellpadding="0" cellspacing="0" width="100%"><tr><td style="background:transparent;border-width:0px;padding:0px;"> </td><td align="right" style="background:transparent;border-width:0px;padding:0px;width:107px" width="107"><a href="http://clipmarks.com/share/879D77BB-AB43-4BA1-9351-526CE699CD4E/blog/" title="blog or email this clip"><img src="http://content7.clipmarks.com/images/c2b-foot.png" border="0" alt="blog it" width="107" height="17" style="border-width:0px;padding:0px;margin:0px;" /></a></td></tr></table></div></div>
New from the makers of Clipmarks:
Amplify.com - Don't just share the news...Amplify it!
Clipmarks
Home
New Clips
Top Clips
Dashboard
Popular Topics
News
Life
Science
Technology
Entertainment
Get Started
Sign Up
Install Clipping Tool
How Clipping Works
Clip-to-Blog™
ClipSearch
Tools and Resources
FAQ
ClipWeek
Top Clippers
Top Tags
Site Map
About Clipmarks
About Us
Contact
Copyright
Privacy
EULA
OK